Class: JsonApi::Associations::ToOne
- Inherits:
-
JsonApi::Association
- Object
- JsonApi::Association
- JsonApi::Associations::ToOne
- Defined in:
- lib/json_api_ruby/associations/to_one.rb
Overview
convenience classes
Instance Attribute Summary
Attributes inherited from JsonApi::Association
#explicit_resource_class, #included, #name, #parent, #parent_model, #resources
Instance Method Summary collapse
- #build_resources(options) ⇒ Object
- #cardinality ⇒ Object
- #data(options = {}) ⇒ Object
- #resource_object ⇒ Object
Methods inherited from JsonApi::Association
#included?, #initialize, #relationship_links, #to_hash
Constructor Details
This class inherits a constructor from JsonApi::Association
Instance Method Details
#build_resources(options) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/json_api_ruby/associations/to_one.rb', line 10 def build_resources() return unless included? resource_model = parent_model.send(name) return if resource_model.blank? resource_class = JsonApi::Resources::Discovery.resource_for_name(resource_model, .merge(parent_resource: parent, resource_class: explicit_resource_class)) @resources << resource_class.new(resource_model, .merge({include: included.next})) end |
#cardinality ⇒ Object
23 24 25 |
# File 'lib/json_api_ruby/associations/to_one.rb', line 23 def cardinality :one end |
#data(options = {}) ⇒ Object
5 6 7 8 |
# File 'lib/json_api_ruby/associations/to_one.rb', line 5 def data(={}) identifier_hash = resource_object.identifier_hash if resource_object {'data' => identifier_hash} end |
#resource_object ⇒ Object
19 20 21 |
# File 'lib/json_api_ruby/associations/to_one.rb', line 19 def resource_object @resources.first end |