lib/dm-pg-json/property/pgjson.rb in dm-pg-json-0.2.0 vs lib/dm-pg-json/property/pgjson.rb in dm-pg-json-0.2.1
- old
+ new
@@ -3,11 +3,12 @@
require 'dm-core'
require 'dm-types/support/dirty_minder'
module DataMapper
class Property
- class PgJSON < Object
+ class PgJSON
+ include ::DataMapper::Property::DirtyMinder
def dump(value)
case value
when ::NilClass, ::String
value
when ::Hash, ::Array
@@ -22,15 +23,16 @@
when ::Hash, ::Array
value
when ::String
Oj.load(value)
else
- {}
+ nil
end
end
def primitive?(value)
- value.kind_of?(::String)
+ value = load(value) if value.kind_of?(::String)
+ value.kind_of?(::Array) || value.kind_of?(::Hash)
end
end
end
end