class Trogdir::V1::PersonEntity
Constants
- FIELDS
Public Instance Methods
serializable_hash(runtime_options = {})
click to toggle source
# File lib/trogdir/versions/v1/entities/person.rb, line 90 def serializable_hash(runtime_options = {}) build_hash(object, FIELDS) end
Private Instance Methods
build_hash(object, fields)
click to toggle source
# File lib/trogdir/versions/v1/entities/person.rb, line 96 def build_hash(object, fields) fields.each_with_object({}) do |field, hash| if field.is_a? Hash field.each do |association, embed_fields| hash[association] = object.send(association).map do |embed| build_hash(embed, embed_fields) end end else # BSON::ObjectId#to_json spits out {:$oid=>"5432cb0862757357e4100000"} # but we want a simple string like "5432cb0862757357e4100000". val = object.send(field) hash[field] = val.is_a?(BSON::ObjectId) ? val.to_s : val end end end