class DatoDump::JsonApiEntity

Attributes

data_source[R]
payload[R]

Public Class Methods

new(payload, data_source) click to toggle source
# File lib/dato_dump/json_api_entity.rb, line 5
def initialize(payload, data_source)
  @payload = payload
  @data_source = data_source
end

Public Instance Methods

==(other) click to toggle source
# File lib/dato_dump/json_api_entity.rb, line 18
def ==(other)
  if other.is_a? JsonApiEntity
    id == other.id && type == other.type
  else
    false
  end
end
[](key) click to toggle source
# File lib/dato_dump/json_api_entity.rb, line 31
def [](key)
  attributes[key]
end
attributes() click to toggle source
# File lib/dato_dump/json_api_entity.rb, line 43
def attributes
  @payload.fetch(:attributes, {})
end
id() click to toggle source
# File lib/dato_dump/json_api_entity.rb, line 10
def id
  @payload[:id]
end
inspect()
Alias for: to_s
respond_to?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/dato_dump/json_api_entity.rb, line 35
def respond_to?(method, include_private = false)
  if attributes.key?(method) || relationships.key?(method)
    true
  else
    super
  end
end
to_s() click to toggle source
# File lib/dato_dump/json_api_entity.rb, line 26
def to_s
  "#<JsonApiEntity id=#{id} type=#{type} payload=#{payload}>"
end
Also aliased as: inspect
type() click to toggle source
# File lib/dato_dump/json_api_entity.rb, line 14
def type
  @payload[:type]
end

Private Instance Methods

dereference_linkage(linkage) click to toggle source
# File lib/dato_dump/json_api_entity.rb, line 53
def dereference_linkage(linkage)
  if linkage.is_a? Array
    linkage.map do |item|
      data_source.find_entity(item[:type], item[:id])
    end
  else
    data_source.find_entity(linkage[:type], linkage[:id])
  end
end
method_missing(method, *arguments, &block) click to toggle source
Calls superclass method
# File lib/dato_dump/json_api_entity.rb, line 63
def method_missing(method, *arguments, &block)
  return super unless arguments.empty?

  if attributes.key?(method)
    attributes[method]
  elsif relationships.key?(method)
    dereference_linkage(relationships[method][:data])
  else
    super
  end
end
relationships() click to toggle source
# File lib/dato_dump/json_api_entity.rb, line 49
def relationships
  @payload.fetch(:relationships, {})
end