Class: JsonApiResource::Associations::Preloaders::Distributors::DistributorByTargetId
- Inherits:
-
Base
- Object
- Base
- JsonApiResource::Associations::Preloaders::Distributors::DistributorByTargetId
show all
- Defined in:
- lib/json_api_resource/associations/preloaders/distributors/distributor_by_target_id.rb
Instance Attribute Summary
Attributes inherited from Base
#association
Instance Method Summary
collapse
Methods inherited from Base
#distribute, #initialize
Instance Method Details
#assign(targets, results) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/json_api_resource/associations/preloaders/distributors/distributor_by_target_id.rb', line 7
def assign( targets, results )
targets.each do |target|
ids = Array(target.send(key))
next unless ids.present?
result = results.select{ |r| ids.include? r.id }
target._cached_associations ||= {}
target._cached_associations[name] = post_process result
end
end
|
#validate_assignability!(results) ⇒ Object
23
24
25
26
27
|
# File 'lib/json_api_resource/associations/preloaders/distributors/distributor_by_target_id.rb', line 23
def validate_assignability!( results )
results.each do |obj|
raise_unless obj.respond_to?(:id), "preloading #{root}.#{name} failed: results don't respond to 'id'"
end
end
|