Class: DataMapper::Property::PgJSON

Inherits:
Object
  • Object
show all
Includes:
DirtyMinder
Defined in:
lib/dm-pg-json/property/pgjson.rb

Instance Method Summary collapse

Instance Method Details

#dump(value) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/dm-pg-json/property/pgjson.rb', line 10

def dump(value)
  case value
  when ::NilClass, ::String
    value
  when ::Hash, ::Array
    Oj.dump(value, mode: :compat)
  else
    '{}'
  end
end

#load(value) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/dm-pg-json/property/pgjson.rb', line 21

def load(value)
  case value
  when ::Hash, ::Array
    value
  when ::String
    Oj.load(value)
  else
    nil
  end
end

#primitive?(value) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/dm-pg-json/property/pgjson.rb', line 32

def primitive?(value)
  value = load(value) if value.kind_of?(::String)
  value.kind_of?(::Array) || value.kind_of?(::Hash)
end