Class: Locomotive::PageTreeService
- Inherits:
-
Struct
- Object
- Struct
- Locomotive::PageTreeService
- Defined in:
- app/services/locomotive/page_tree_service.rb
Instance Attribute Summary collapse
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
-
#build_tree ⇒ Array
Returns the tree of pages from the site with the most minimal amount of queries.
Instance Attribute Details
#site ⇒ Object
Returns the value of attribute site
3 4 5 |
# File 'app/services/locomotive/page_tree_service.rb', line 3 def site @site end |
Instance Method Details
#build_tree ⇒ Array
Returns the tree of pages from the site with the most minimal amount of queries. This method should only be used for read-only purpose since the mongodb returns the minimal set of required attributes to build the tree.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/services/locomotive/page_tree_service.rb', line 12 def build_tree pages, page_not_found = pages_with_minimun_attributes, nil [].tap do |tree| while page = pages.shift if page.not_found? # move the "page not found" (404) at the end of the array page_not_found = page elsif page.index? # make the index page without children tree << [page, nil] elsif !page. tree << _build_tree(page, pages) end end tree << [page_not_found, nil] end end |