lib/dm-pg-json/property/pgjson.rb in dm-pg-json-0.0.1 vs lib/dm-pg-json/property/pgjson.rb in dm-pg-json-0.1.0
- old
+ new
@@ -1,15 +1,36 @@
# encoding: utf-8
+require 'dm-core'
+require 'dm-types/support/dirty_minder'
+
module DataMapper
class Property
- class PgJSON < Property
+ class PgJSON < Text
+ def dump(value)
+ case value
+ when ::NilClass, ::String
+ value
+ when ::Hash, ::Array
+ Oj.dump(value, mode: :compat)
+ else
+ '{}'
+ end
+ end
+
def load(value)
- Oj.load(value)
+ case value
+ when ::Hash, ::Array
+ value
+ when ::String
+ Oj.load(value)
+ else
+ {}
+ end
end
- def dump(value)
- Oj.dump(value, mode: :compat)
+ def primitive?(value)
+ value.kind_of?(::String)
end
end
end
end