class Dato::Local::JsonApiEntity
Attributes
data_source[R]
payload[R]
Public Class Methods
new(payload, data_source)
click to toggle source
# File lib/dato/local/json_api_entity.rb, line 10 def initialize(payload, data_source) @payload = payload @data_source = data_source end
Public Instance Methods
==(other)
click to toggle source
# File lib/dato/local/json_api_entity.rb, line 27 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/local/json_api_entity.rb, line 40 def [](key) attributes[key.to_sym] end
id()
click to toggle source
# File lib/dato/local/json_api_entity.rb, line 15 def id @payload[:id] end
meta()
click to toggle source
# File lib/dato/local/json_api_entity.rb, line 23 def meta @meta ||= JsonApiMeta.new(@payload[:meta]) end
respond_to_missing?(method, include_private = false)
click to toggle source
Calls superclass method
# File lib/dato/local/json_api_entity.rb, line 44 def respond_to_missing?(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/local/json_api_entity.rb, line 35 def to_s "#<JsonApiEntity id=#{id} type=#{type} payload=#{payload}>" end
Also aliased as: inspect
type()
click to toggle source
# File lib/dato/local/json_api_entity.rb, line 19 def type @payload[:type] end
Private Instance Methods
attributes()
click to toggle source
# File lib/dato/local/json_api_entity.rb, line 54 def attributes @payload.fetch(:attributes, {}) end
dereference_linkage(linkage)
click to toggle source
# File lib/dato/local/json_api_entity.rb, line 62 def dereference_linkage(linkage) case linkage when Array linkage.map do |item| data_source.find_entity(item[:type], item[:id]) end when Hash 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/local/json_api_entity.rb, line 73 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/local/json_api_entity.rb, line 58 def relationships @payload.fetch(:relationships, {}) end