Parent

DataMapper::Property::Json

Public Instance Methods

custom?() click to toggle source
# File lib/dm-types/json.rb, line 9
def custom?
  true
end
dump(value) click to toggle source
# File lib/dm-types/json.rb, line 31
def dump(value)
  if value.nil? || value.is_a?(::String)
    value
  else
    MultiJson.encode(value)
  end
end
load(value) click to toggle source
# File lib/dm-types/json.rb, line 21
def load(value)
  if value.nil?
    nil
  elsif value.is_a?(::String)
    typecast_to_primitive(value)
  else
    raise ArgumentError.new("+value+ of a property of JSON type must be nil or a String")
  end
end
primitive?(value) click to toggle source
# File lib/dm-types/json.rb, line 13
def primitive?(value)
  value.kind_of?(::Array) || value.kind_of?(::Hash)
end
typecast_to_primitive(value) click to toggle source
# File lib/dm-types/json.rb, line 39
def typecast_to_primitive(value)
  MultiJson.decode(value.to_s)
end
valid?(value, negated = false) click to toggle source
# File lib/dm-types/json.rb, line 17
def valid?(value, negated = false)
  super || dump(value).kind_of?(::String)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.