class JSONAPI::Consumer::Relationships::Relations
Attributes
record_class[R]
Public Class Methods
new(record_class, relations)
click to toggle source
# File lib/jsonapi/consumer/relationships/relations.rb, line 11 def initialize(record_class, relations) @record_class = record_class self.attributes = relations clear_changes_information end
Public Instance Methods
as_json()
click to toggle source
# File lib/jsonapi/consumer/relationships/relations.rb, line 27 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/jsonapi/consumer/relationships/relations.rb, line 21 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/jsonapi/consumer/relationships/relations.rb, line 33 def attributes_for_serialization attributes.slice(*changed) end
present?()
click to toggle source
# File lib/jsonapi/consumer/relationships/relations.rb, line 17 def present? attributes.present? end
Protected Instance Methods
set_attribute(name, value)
click to toggle source
# File lib/jsonapi/consumer/relationships/relations.rb, line 39 def set_attribute(name, value) value = case value when JSONAPI::Consumer::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