File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,20 @@ module CouchbaseOrm
2
2
module Types
3
3
class Timestamp < ActiveModel ::Type ::DateTime
4
4
def cast ( value )
5
- value = super ( value )
6
- return nil if value . nil?
7
- return Time . at ( value ) if value . is_a? ( Integer ) || value . is_a? ( Float )
8
- return Time . at ( value . to_i ) if value . is_a? ( String ) && value =~ /^[0-9]+$/
9
- return value . utc if value . is_a? ( Time )
5
+ return nil if value . nil?
6
+
7
+ value = if value . is_a? ( Integer ) || value . is_a? ( Float )
8
+ Time . at ( value )
9
+ elsif value . is_a? ( String ) && value =~ /^[0-9]+$/
10
+ Time . at ( value . to_i )
11
+ elsif value . is_a? ( Time )
12
+ value . utc
13
+ else
14
+ value
15
+ end
16
+ super ( value )
10
17
end
11
-
18
+
12
19
def serialize ( value )
13
20
value &.to_i
14
21
end
Original file line number Diff line number Diff line change @@ -117,13 +117,13 @@ def build_not_match(key, value)
117
117
end
118
118
119
119
def serialize_value ( key , value_before_type_cast )
120
- value =
120
+ value =
121
121
if value_before_type_cast . is_a? ( Array )
122
122
value_before_type_cast . map do |v |
123
- attribute_types [ key . to_s ] . serialize ( v )
123
+ attribute_types [ key . to_s ] . serialize ( attribute_types [ key . to_s ] . cast ( v ) )
124
124
end
125
125
else
126
- attribute_types [ key . to_s ] . serialize ( value_before_type_cast )
126
+ attribute_types [ key . to_s ] . serialize ( attribute_types [ key . to_s ] . cast ( value_before_type_cast ) )
127
127
end
128
128
CouchbaseOrm . logger . debug { "convert_values: #{ key } => #{ value_before_type_cast . inspect } => #{ value . inspect } #{ value . class } #{ attribute_types [ key . to_s ] } " }
129
129
value
You can’t perform that action at this time.
0 commit comments