Sha256: 39309aba19088c4e6bc4f5db0f86ba4e7f1119c46dbf658e12633e29aac911d4
Contents?: true
Size: 1.22 KB
Versions: 2
Compression:
Stored size: 1.22 KB
Contents
module DataMapper module Model # module Json def to_json_schema(repository_name = default_repository_name) to_json_schema_compatible_hash(repository_name).to_json end #TODO: Add various options in. def to_json_schema_compatible_hash(repository_name = default_repository_name) usable_properties = properties.select{|p| p.name != :id } schema_hash = {} schema_hash['id'] = self.storage_name(repository_name) properties_hash = {} usable_properties.each{|p| properties_hash[p.name] = p.to_json_schema_hash(repository_name) if p.name != :id } schema_hash['properties'] = properties_hash schema_hash['prototype'] = {} return schema_hash end end class Property def to_json_schema_hash(repo) tm = repository(repo).adapter.type_map json_hash = { "type" => tm[type][:primitive] } json_hash.merge!( tm[type].reject{ |key,value| key == :primitive } ) json_hash.merge!({ "optional" => true }) unless required? == true json_hash.merge!({ "unique" => true}) if unique? == true json_hash.merge!({"position" => @position }) unless @position.nil? # MIN # MAX json_hash end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dm-persevere-adapter-0.40.0 | lib/model_json_support.rb |
dm-persevere-adapter-0.39.0 | lib/model_json_support.rb |