Class: Primalize::JSONAPI::HasMany
- Inherits:
-
Object
- Object
- Primalize::JSONAPI::HasMany
- Defined in:
- lib/primalize/jsonapi.rb
Instance Attribute Summary collapse
-
#attr ⇒ Object
readonly
Returns the value of attribute attr.
Instance Method Summary collapse
- #call(model, cache:) ⇒ Object
-
#initialize(attr, type: attr, &block) ⇒ HasMany
constructor
A new instance of HasMany.
- #metadata(model, cache:) ⇒ Object
- #primalizer ⇒ Object
Constructor Details
Instance Attribute Details
#attr ⇒ Object (readonly)
Returns the value of attribute attr.
61 62 63 |
# File 'lib/primalize/jsonapi.rb', line 61 def attr @attr end |
Instance Method Details
#call(model, cache:) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/primalize/jsonapi.rb', line 67 def call(model, cache:) model.send(@attr).map do |obj| cache.fetch(:serialization, obj) do primalizer.new(obj).call end end end |
#metadata(model, cache:) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/primalize/jsonapi.rb', line 79 def (model, cache:) result = model.send(@attr).map do |obj| cache.fetch(:metadata, obj) do MetadataPrimalizer.new(obj, primalizer.type).call end end { data: result } end |
#primalizer ⇒ Object
75 76 77 |
# File 'lib/primalize/jsonapi.rb', line 75 def primalizer @primalizer ||= @block.call end |