class JsonApiClient::Relationships::Relations
Attributes
record_class[R]
Public Class Methods
new(record_class, relations)
click to toggle source
# File lib/json_api_client/relationships/relations.rb, line 11 def initialize(record_class, relations) @record_class = record_class self.attributes = relations end
Public Instance Methods
as_json()
click to toggle source
# File lib/json_api_client/relationships/relations.rb, line 26 def as_json Hash[attributes.map do |k, v| [k, v.slice("data")] if v.has_key?("data") end.compact] end
as_json_api()
click to toggle source
# File lib/json_api_client/relationships/relations.rb, line 20 def as_json_api Hash[attributes_for_serialization.map do |k, v| [k, v.slice("data")] if v.has_key?("data") end.compact] end
attributes_for_serialization()
click to toggle source
# File lib/json_api_client/relationships/relations.rb, line 32 def attributes_for_serialization attributes.slice(*changed) end
present?()
click to toggle source
# File lib/json_api_client/relationships/relations.rb, line 16 def present? attributes.present? end
Protected Instance Methods
set_attribute(name, value)
click to toggle source
# File lib/json_api_client/relationships/relations.rb, line 38 def set_attribute(name, value) value = case value when JsonApiClient::Resource {data: value.as_relation} when Array {data: value.map(&:as_relation)} when NilClass {data: nil} else value end attribute_will_change!(name) if value != attributes[name] attributes[name] = value end