Class: JsonApiModel::Associations::Base
- Inherits:
-
Object
- Object
- JsonApiModel::Associations::Base
- Defined in:
- lib/json_api_model/associations/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#base_class ⇒ Object
Returns the value of attribute base_class.
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
- #association_class ⇒ Object
- #fetch(instance) ⇒ Object
-
#initialize(base_class, name, opts = {}) ⇒ Base
constructor
A new instance of Base.
- #json_relationship? ⇒ Boolean
- #process(results) ⇒ Object
Constructor Details
#initialize(base_class, name, opts = {}) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 14 15 |
# File 'lib/json_api_model/associations/base.rb', line 8 def initialize( base_class, name, opts = {} ) self.name = name self.opts = opts self.key = idify( base_class ) self.base_class = base_class validate_opts! end |
Instance Attribute Details
#base_class ⇒ Object
Returns the value of attribute base_class.
5 6 7 |
# File 'lib/json_api_model/associations/base.rb', line 5 def base_class @base_class end |
#key ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/json_api_model/associations/base.rb', line 5 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/json_api_model/associations/base.rb', line 5 def name @name end |
#opts ⇒ Object
Returns the value of attribute opts.
5 6 7 |
# File 'lib/json_api_model/associations/base.rb', line 5 def opts @opts end |
Instance Method Details
#association_class ⇒ Object
25 26 27 28 29 |
# File 'lib/json_api_model/associations/base.rb', line 25 def association_class @associated_class ||= opts[:class] || opts[:class_name]&.constantize || derived_class end |
#fetch(instance) ⇒ Object
17 18 19 |
# File 'lib/json_api_model/associations/base.rb', line 17 def fetch( instance ) process association_class.send( action, query( instance ) ) end |
#json_relationship? ⇒ Boolean
21 22 23 |
# File 'lib/json_api_model/associations/base.rb', line 21 def json_relationship? association_class < JsonApiModel::Model end |
#process(results) ⇒ Object
31 32 33 |
# File 'lib/json_api_model/associations/base.rb', line 31 def process( results ) results end |