class Roaster::JsonApi::Mapping
Public Instance Methods
to_hash(option)
click to toggle source
Calls superclass method
# File lib/roaster/json_api.rb, line 31 def to_hash(option) roaster_type = option[:roaster] links = {} representable_attrs[:_has_one].each do |link| representable_attrs[:definitions].delete(link[:name].to_s) links[link[:name]] = @represented[link[:key]].to_s end unless representable_attrs[:_has_one].nil? representable_attrs[:_has_many].each do |link| representable_attrs[:definitions].delete(link[:name].to_s) links[link[:name]] = @represented.send(link[:key]).map(&:to_s) || [] end unless representable_attrs[:_has_many].nil? if roaster_type.nil? resource_id.to_s else sup = {'id' => resource_id.to_s } sup.merge!({'links' => links }) unless links.empty? case roaster_type when :resource { self.class.get_resource_name => sup.merge(super(option)) } when :collection sup.merge(super(option)) end end end