Class: SimpleJsonApi::Member::Included
- Inherits:
-
Object
- Object
- SimpleJsonApi::Member::Included
- Defined in:
- lib/simple_json_api/member/included.rb
Overview
JSONAPI Included top-level member
Instance Method Summary collapse
- #already_included?(resource) ⇒ Boolean
- #content ⇒ Object
- #included?(association) ⇒ Boolean
-
#initialize(root_node, data) ⇒ Included
constructor
A new instance of Included.
- #process(association) ⇒ Object
- #visit(node) ⇒ Object
Constructor Details
#initialize(root_node, data) ⇒ Included
Returns a new instance of Included.
5 6 7 8 9 |
# File 'lib/simple_json_api/member/included.rb', line 5 def initialize(root_node, data) @root_node = root_node @data = data @included = [] end |
Instance Method Details
#already_included?(resource) ⇒ Boolean
33 34 35 |
# File 'lib/simple_json_api/member/included.rb', line 33 def already_included?(resource) @included.include?(resource) || Array(@data).include?(resource) end |
#content ⇒ Object
11 12 13 14 |
# File 'lib/simple_json_api/member/included.rb', line 11 def content visit(@root_node) @included end |
#included?(association) ⇒ Boolean
29 30 31 |
# File 'lib/simple_json_api/member/included.rb', line 29 def included?(association) association.assoc_list[:include].present? end |
#process(association) ⇒ Object
23 24 25 26 27 |
# File 'lib/simple_json_api/member/included.rb', line 23 def process(association) Array[association.serialize].flatten.each do |hash| @included << hash unless already_included? hash end end |
#visit(node) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/simple_json_api/member/included.rb', line 16 def visit(node) node.associations.each do |association| process(association) if included?(association) visit(association) end end |