Class: SatanicPages::PageList
- Inherits:
-
Object
- Object
- SatanicPages::PageList
- Defined in:
- lib/satanic_pages/page_list.rb
Defined Under Namespace
Classes: PageNotFound
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
Instance Method Summary collapse
- #find(path) ⇒ Object
- #find!(path) ⇒ Object
-
#initialize(controller_name) ⇒ PageList
constructor
A new instance of PageList.
- #match?(req_path) ⇒ Boolean
Constructor Details
#initialize(controller_name) ⇒ PageList
Returns a new instance of PageList.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/satanic_pages/page_list.rb', line 8 def initialize(controller_name) @base_path = Rails.root.join("app/views/", controller_name) @pages = Dir[base_path + "**/*.html*"] .reject { |path| path.match?(/(^_|\/_)/) } .each_with_object({}) do |full_path, hash| page = Page.new(full_path, base_path) hash[page.path] = page end end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
19 20 21 |
# File 'lib/satanic_pages/page_list.rb', line 19 def base_path @base_path end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
19 20 21 |
# File 'lib/satanic_pages/page_list.rb', line 19 def pages @pages end |
Instance Method Details
#find(path) ⇒ Object
27 28 29 30 31 |
# File 'lib/satanic_pages/page_list.rb', line 27 def find(path) find!(path) rescue PageNotFound nil end |
#find!(path) ⇒ Object
21 22 23 24 25 |
# File 'lib/satanic_pages/page_list.rb', line 21 def find!(path) @pages.fetch(path) rescue KeyError raise PageNotFound, "No page `#{path}' found at #{base_path}" end |
#match?(req_path) ⇒ Boolean
33 34 35 36 |
# File 'lib/satanic_pages/page_list.rb', line 33 def match?(req_path) path = req_path.gsub(/^\//, "") pages.keys.include?(path) end |