Class: JSONAPI::Consumer::Relationships::Relations
- Inherits:
-
Object
- Object
- JSONAPI::Consumer::Relationships::Relations
- Includes:
- ActiveModel::Serialization, Helpers::Dirty, Helpers::DynamicAttributes
- Defined in:
- lib/jsonapi/consumer/relationships/relations.rb
Instance Attribute Summary collapse
-
#record_class ⇒ Object
readonly
Returns the value of attribute record_class.
Instance Method Summary collapse
- #as_json ⇒ Object
- #as_json_api ⇒ Object
- #attributes_for_serialization ⇒ Object
-
#initialize(record_class, relations) ⇒ Relations
constructor
A new instance of Relations.
- #present? ⇒ Boolean
Methods included from Helpers::Dirty
#attribute_change, #attribute_changed?, #attribute_was, #attribute_will_change!, #changed, #changed?, #changed_attributes, #clear_changes_information, #set_all_attributes_dirty, #set_attribute_was
Methods included from Helpers::DynamicAttributes
#[], #[]=, #attributes, #attributes=, #has_attribute?, #respond_to_missing?
Constructor Details
#initialize(record_class, relations) ⇒ Relations
Returns a new instance of Relations.
11 12 13 14 15 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class JSONAPI::Consumer::Helpers::Dirty
Instance Attribute Details
#record_class ⇒ Object (readonly)
Returns the value of attribute record_class.
8 9 10 |
# File 'lib/jsonapi/consumer/relationships/relations.rb', line 8 def record_class @record_class end |
Instance Method Details
#as_json ⇒ Object
27 28 29 30 31 |
# 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 ⇒ Object
21 22 23 24 25 |
# 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 ⇒ Object
33 34 35 |
# File 'lib/jsonapi/consumer/relationships/relations.rb', line 33 def attributes_for_serialization attributes.slice(*changed) end |
#present? ⇒ Boolean
17 18 19 |
# File 'lib/jsonapi/consumer/relationships/relations.rb', line 17 def present? attributes.present? end |