Skip to content

Commit a181cfc

Browse files
committed
Fix weird implem
1 parent 53f052e commit a181cfc

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

lib/couchbase-orm/changeable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def create_dirty_methods(name, meth)
368368
def create_setters(name)
369369
define_method("#{name}=") do |new_attribute_value|
370370
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
372372
previous_value = attributes[name.to_s]
373373
ret = super(casted_value)
374374
if previous_value != attributes[name.to_s]

lib/couchbase-orm/types/timestamp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ module CouchbaseOrm
22
module Types
33
class Timestamp < ActiveModel::Type::DateTime
44
def cast(value)
5+
value = super(value)
56
return nil if value.nil?
67
return Time.at(value) if value.is_a?(Integer) || value.is_a?(Float)
78
return Time.at(value.to_i) if value.is_a?(String) && value =~ /^[0-9]+$/
89
return value.utc if value.is_a?(Time)
9-
super(value).utc
1010
end
1111

1212
def serialize(value)

spec/type_spec.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@
44
require "couchbase-orm/types"
55

66
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
1021
end
1122

1223
ActiveModel::Type.register(:datetime3decimal, DateTimeWith3Decimal)
@@ -17,7 +28,7 @@ class TypeTest < CouchbaseOrm::Base
1728
attribute :size, :float
1829
attribute :renewal_date, :date
1930
attribute :subscribed_at, :datetime
20-
attribute :some_time, :timestamp
31+
attribute :some_time, :timestamp, precision: 0
2132
attribute :precision3_time, :datetime3decimal
2233
attribute :precision6_time, :datetime, precision: 6
2334

0 commit comments

Comments
 (0)