class DataMapper::Property::PgJSON

Attributes

load_raw_value[R]

Public Class Methods

new(model, name, options = {}) click to toggle source
Calls superclass method
# File lib/dm-postgres-types/property/pg_json.rb, line 11
def initialize(model, name, options = {})
  super
  @load_raw_value = @options[:load_raw_value] || false
end

Public Instance Methods

dump(value) click to toggle source
# File lib/dm-postgres-types/property/pg_json.rb, line 16
def dump(value)
  case value
  when ::NilClass, ::String
    value
  when ::Hash, ::Array
    Oj.dump(value, mode: :compat)
  else
    '{}'
  end
end
load(value) click to toggle source
# File lib/dm-postgres-types/property/pg_json.rb, line 27
def load(value)
  case value
  when ::Hash, ::Array
    (load_raw_value) ? Oj.dump(value, mode: :compat) : value
  when ::String
    (load_raw_value) ? value : Oj.load(value)
  else
    (load_raw_value) ? '{}' : {}
  end
end
primitive?(value) click to toggle source
# File lib/dm-postgres-types/property/pg_json.rb, line 38
def primitive?(value)
  value.kind_of?(::String)
end