File tree Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -368,7 +368,7 @@ def create_dirty_methods(name, meth)
368
368
def create_setters ( name )
369
369
define_method ( "#{ name } =" ) do |new_attribute_value |
370
370
type = self . class . attribute_types [ name . to_s ]
371
- casted_value = type . cast ( type . serialize type . cast new_attribute_value )
371
+ casted_value = type . cast new_attribute_value
372
372
previous_value = attributes [ name . to_s ]
373
373
ret = super ( casted_value )
374
374
if previous_value != attributes [ name . to_s ]
Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ module CouchbaseOrm
2
2
module Types
3
3
class Timestamp < ActiveModel ::Type ::DateTime
4
4
def cast ( value )
5
+ value = super ( value )
5
6
return nil if value . nil?
6
7
return Time . at ( value ) if value . is_a? ( Integer ) || value . is_a? ( Float )
7
8
return Time . at ( value . to_i ) if value . is_a? ( String ) && value =~ /^[0-9]+$/
8
9
return value . utc if value . is_a? ( Time )
9
- super ( value ) . utc
10
10
end
11
11
12
12
def serialize ( value )
Original file line number Diff line number Diff line change 4
4
require "couchbase-orm/types"
5
5
6
6
class DateTimeWith3Decimal < CouchbaseOrm ::Types ::DateTime
7
- def serialize ( value )
8
- value &.iso8601 ( 3 )
9
- end
7
+ def initialize
8
+ super
9
+ @precision = 3
10
+ end
11
+ # def serialize(value)
12
+ # value&.iso8601(precision)
13
+ # end
14
+ # def cast(value)
15
+ # value = super(value)
16
+ # return nil if value.nil?
17
+ # return Time.at(value) if value.is_a?(Integer) || value.is_a?(Float)
18
+ # return Time.at(value.to_i) if value.is_a?(String) && value =~ /^[0-9]+$/
19
+ # return value if value.is_a?(Time)
20
+ # end
10
21
end
11
22
12
23
ActiveModel ::Type . register ( :datetime3decimal , DateTimeWith3Decimal )
@@ -17,7 +28,7 @@ class TypeTest < CouchbaseOrm::Base
17
28
attribute :size , :float
18
29
attribute :renewal_date , :date
19
30
attribute :subscribed_at , :datetime
20
- attribute :some_time , :timestamp
31
+ attribute :some_time , :timestamp , precision : 0
21
32
attribute :precision3_time , :datetime3decimal
22
33
attribute :precision6_time , :datetime , precision : 6
23
34
You can’t perform that action at this time.
0 commit comments