Class: Primalize::JSONAPI::HasOne
- Inherits:
-
Object
- Object
- Primalize::JSONAPI::HasOne
- 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) ⇒ HasOne
constructor
A new instance of HasOne.
- #metadata(model, cache:) ⇒ Object
- #primalizer ⇒ Object
Constructor Details
Instance Attribute Details
#attr ⇒ Object (readonly)
Returns the value of attribute attr.
91 92 93 |
# File 'lib/primalize/jsonapi.rb', line 91 def attr @attr end |
Instance Method Details
#call(model, cache:) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/primalize/jsonapi.rb', line 97 def call(model, cache:) model = model.send(@attr) cache.fetch(:serialization, model) do primalizer.new(model).call end end |
#metadata(model, cache:) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/primalize/jsonapi.rb', line 108 def (model, cache:) model = model.send(@attr) data = cache.fetch(:metadata, model) do MetadataPrimalizer.new(model, primalizer.type).call end { data: data } end |
#primalizer ⇒ Object
104 105 106 |
# File 'lib/primalize/jsonapi.rb', line 104 def primalizer @primalizer ||= @block.call end |