class DIDWW::Resource::Base

Public Instance Methods

as_json_api(*args) click to toggle source
Calls superclass method
# File lib/didww/resources/base.rb, line 7
def as_json_api(*args)
  serialize_complex_attributes(super(*args))
end

Private Instance Methods

serialize_complex_attributes(hash) click to toggle source
# File lib/didww/resources/base.rb, line 13
def serialize_complex_attributes(hash)
  # Replace complex objects with their json_api representation
  attributes = hash[:attributes]
  hash[:attributes] = Hash[attributes.map do |k, v|
    if v.respond_to?(:as_json_api)
      [k, v.as_json_api]
    elsif v.is_a?(Array)
      [k, v.map { |i| i.respond_to?(:as_json_api) ? i.as_json_api : i }]
    else
      [k, v]
    end
  end].with_indifferent_access
  return hash
end