Module: DataMapper::Persevere::JSONSupport::Property

Defined in:
lib/persevere_adapter/json_support/property.rb

Instance Method Summary collapse

Instance Method Details

#to_json_hash(repo) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/persevere_adapter/json_support/property.rb', line 5

def to_json_hash(repo)
  tm = repository(repo).adapter.type_map
  type_information = tm[primitive]
  
  json_hash = Hash.new
  json_hash = {      "type"      => type_information[:primitive] }
  json_hash.merge!({ "optional"  => true })       unless required?
  json_hash.merge!({ "unique"    => true})        if     unique?
  json_hash.merge!({ "position"  => @position })  unless @position.nil?
  json_hash.merge!({ "prefix"    => @prefix })    unless @prefix.nil?
  json_hash.merge!({ "separator" => @separator }) unless @separator.nil?
  json_hash.merge!(  type_information.reject{ |key,value| key == :primitive } )

  json_hash
end