Class: Udongo::Pages::Tree
- Inherits:
-
Object
- Object
- Udongo::Pages::Tree
- Defined in:
- lib/udongo/pages/tree.rb
Instance Method Summary collapse
- #data(parent_id: nil) ⇒ Object
-
#initialize(context) ⇒ Tree
constructor
A new instance of Tree.
Constructor Details
#initialize(context) ⇒ Tree
Returns a new instance of Tree.
3 4 5 |
# File 'lib/udongo/pages/tree.rb', line 3 def initialize(context) @context = context end |
Instance Method Details
#data(parent_id: nil) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/udongo/pages/tree.rb', line 7 def data(parent_id: nil) Page.where(parent_id: parent_id).inject([]) do |results, page| hash = Udongo::Pages::TreeNode.new(@context, page).data hash[:children] = data(parent_id: page.id) if page.children.any? results << hash end end |