Class: JsonApiModel::Associations::Preloaders::Base
- Inherits:
-
Object
- Object
- JsonApiModel::Associations::Preloaders::Base
- Defined in:
- lib/json_api_model/associations/preloaders/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#association ⇒ Object
Returns the value of attribute association.
Instance Method Summary collapse
- #assign(results) ⇒ Object
- #fetch ⇒ Object
-
#initialize(objects, association) ⇒ Base
constructor
A new instance of Base.
- #load ⇒ Object
Constructor Details
#initialize(objects, association) ⇒ Base
Returns a new instance of Base.
9 10 11 12 |
# File 'lib/json_api_model/associations/preloaders/base.rb', line 9 def initialize( objects, association ) @objects = Array( objects ) @association = association end |
Instance Attribute Details
#association ⇒ Object
Returns the value of attribute association.
6 7 8 |
# File 'lib/json_api_model/associations/preloaders/base.rb', line 6 def association @association end |
Instance Method Details
#assign(results) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/json_api_model/associations/preloaders/base.rb', line 22 def assign( results ) validate_assignability!( results ) @objects.each do | object | associated_objects = results.to_a.select do |r| associated_key( r ).in? Array( ids( object ) ) end object.send( "#{name}=", process( associated_objects ) ) end end |
#fetch ⇒ Object
14 15 16 |
# File 'lib/json_api_model/associations/preloaders/base.rb', line 14 def fetch assign load end |
#load ⇒ Object
18 19 20 |
# File 'lib/json_api_model/associations/preloaders/base.rb', line 18 def load association_class.send( action, query( @objects ) ) end |