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.
8 9 10 11 |
# File 'lib/primalize/jsonapi.rb', line 8 def initialize @rels = [] @map = {} end |
Instance Method Details
#<<(rel) ⇒ Object
13 14 15 16 |
# File 'lib/primalize/jsonapi.rb', line 13 def << rel @rels << rel @map[rel.attr] = rel end |
#[](rel) ⇒ Object
18 19 20 |
# File 'lib/primalize/jsonapi.rb', line 18 def [] rel @map[rel] end |
#call(model, cache:) ⇒ Object
28 29 30 31 32 |
# File 'lib/primalize/jsonapi.rb', line 28 def call(model, cache:) @rels.each_with_object({}) do |rel, hash| hash[rel.attr] = rel.call(model) end end |
#metadata(model, cache:) ⇒ Object
22 23 24 25 26 |
# File 'lib/primalize/jsonapi.rb', line 22 def (model, cache:) @rels.each_with_object({}) do |rel, hash| hash[rel.attr] = rel.(model, cache: cache) end end |