class Refinery::Pages::FinderByScopedPath

Public Instance Methods

find() click to toggle source
# File lib/refinery/pages/finder.rb, line 119
def find
  # With slugs scoped to the parent page we need to find a page by its full path.
  # For example with about/example we would need to find 'about' and then its child
  # called 'example' otherwise it may clash with another page called /example.
  page = parent_page
  while page && path_segments.any? do
    page = next_page(page)
  end
  page
end

Private Instance Methods

next_page(page) click to toggle source
# File lib/refinery/pages/finder.rb, line 145
def next_page(page)
  slug_or_id = path_segments.shift
  page.children.by_slug(slug_or_id).first || page.children.find(slug_or_id)
end
parent_page() click to toggle source
# File lib/refinery/pages/finder.rb, line 136
def parent_page
  parent_page_segment = path_segments.shift
  if parent_page_segment.friendly_id?
    by_slug(parent_page_segment, :parent_id => nil).first
  else
    Page.find(parent_page_segment)
  end
end
path_segments() click to toggle source
# File lib/refinery/pages/finder.rb, line 132
def path_segments
  @path_segments ||= path.split('/').select(&:present?)
end