Class: AbcJsonapi::Model
- Inherits:
-
Object
- Object
- AbcJsonapi::Model
- Defined in:
- lib/abc_jsonapi/model.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#relationships ⇒ Object
readonly
Returns the value of attribute relationships.
-
#resource_attributes ⇒ Object
readonly
Returns the value of attribute resource_attributes.
-
#resource_type ⇒ Object
readonly
Returns the value of attribute resource_type.
-
#virtual_attributes ⇒ Object
readonly
Returns the value of attribute virtual_attributes.
Instance Method Summary collapse
-
#initialize(model:, resource_type:, resource_attributes:, virtual_attributes:, relationships:) ⇒ Model
constructor
A new instance of Model.
- #serializable_hash ⇒ Object
Constructor Details
#initialize(model:, resource_type:, resource_attributes:, virtual_attributes:, relationships:) ⇒ Model
Returns a new instance of Model.
8 9 10 11 12 13 14 |
# File 'lib/abc_jsonapi/model.rb', line 8 def initialize(model:, resource_type:, resource_attributes:, virtual_attributes:, relationships:) @model = model @resource_type = resource_type.to_sym @resource_attributes = resource_attributes @virtual_attributes = virtual_attributes @relationships = relationships end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/abc_jsonapi/model.rb', line 6 def model @model end |
#relationships ⇒ Object (readonly)
Returns the value of attribute relationships.
6 7 8 |
# File 'lib/abc_jsonapi/model.rb', line 6 def relationships @relationships end |
#resource_attributes ⇒ Object (readonly)
Returns the value of attribute resource_attributes.
6 7 8 |
# File 'lib/abc_jsonapi/model.rb', line 6 def resource_attributes @resource_attributes end |
#resource_type ⇒ Object (readonly)
Returns the value of attribute resource_type.
6 7 8 |
# File 'lib/abc_jsonapi/model.rb', line 6 def resource_type @resource_type end |
#virtual_attributes ⇒ Object (readonly)
Returns the value of attribute virtual_attributes.
6 7 8 |
# File 'lib/abc_jsonapi/model.rb', line 6 def virtual_attributes @virtual_attributes end |
Instance Method Details
#serializable_hash ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/abc_jsonapi/model.rb', line 16 def serializable_hash data = {} data[:id] = model.id.to_s data[:type] = resource_type data[:attributes] = transform_keys_if_necessary(attributes_hash) data[:relationships] = transform_keys_if_necessary(relationships_hash, true) if relationships.any? data end |