Class: Primalize::JSONAPI::Relationships
- Inherits:
-
Object
- Object
- Primalize::JSONAPI::Relationships
- Defined in:
- lib/primalize/jsonapi.rb
Instance Method Summary collapse
- #<<(rel) ⇒ Object
- #[](rel) ⇒ Object
- #call(model, cache:) ⇒ Object
-
#initialize ⇒ Relationships
constructor
A new instance of Relationships.
- #metadata(model, cache:) ⇒ Object
Constructor Details
#initialize ⇒ Relationships
Returns a new instance of Relationships.
33 34 35 36 |
# File 'lib/primalize/jsonapi.rb', line 33 def initialize @rels = [] @map = {} end |
Instance Method Details
#<<(rel) ⇒ Object
38 39 40 41 |
# File 'lib/primalize/jsonapi.rb', line 38 def << rel @rels << rel @map[rel.attr] = rel end |
#[](rel) ⇒ Object
43 44 45 |
# File 'lib/primalize/jsonapi.rb', line 43 def [] rel @map[rel] end |
#call(model, cache:) ⇒ Object
53 54 55 56 57 |
# File 'lib/primalize/jsonapi.rb', line 53 def call(model, cache:) @rels.each_with_object({}) do |rel, hash| hash[rel.attr] = rel.call(model) end end |
#metadata(model, cache:) ⇒ Object
47 48 49 50 51 |
# File 'lib/primalize/jsonapi.rb', line 47 def (model, cache:) @rels.each_with_object({}) do |rel, hash| hash[rel.attr] = rel.(model, cache: cache) end end |