Class: Mascot::Sitemap
- Inherits:
-
Object
- Object
- Mascot::Sitemap
- Defined in:
- lib/mascot.rb
Overview
A collection of pages from a directory.
Constant Summary collapse
- DEFAULT_GLOB =
Default file pattern to pick up in sitemap
"**/**".freeze
- DEFAULT_ROOT_DIR =
Default root path for sitemap.
Pathname.new(".").freeze
- DEFAULT_ROOT_REQUEST_PATH =
Default root request path
Pathname.new("/").freeze
Instance Attribute Summary collapse
-
#file_path ⇒ Object
Returns the value of attribute file_path.
- #request_path ⇒ Object writeonly
Instance Method Summary collapse
-
#find_by_request_path(request_path) ⇒ Object
Find the page with a path.
-
#initialize(file_path: DEFAULT_ROOT_DIR, request_path: DEFAULT_ROOT_REQUEST_PATH) ⇒ Sitemap
constructor
A new instance of Sitemap.
-
#resources(glob = DEFAULT_GLOB) ⇒ Object
Lazy stream of resources.
Constructor Details
#initialize(file_path: DEFAULT_ROOT_DIR, request_path: DEFAULT_ROOT_REQUEST_PATH) ⇒ Sitemap
Returns a new instance of Sitemap.
90 91 92 93 |
# File 'lib/mascot.rb', line 90 def initialize(file_path: DEFAULT_ROOT_DIR, request_path: DEFAULT_ROOT_REQUEST_PATH) self.file_path = file_path self.request_path = request_path end |
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path.
88 89 90 |
# File 'lib/mascot.rb', line 88 def file_path @file_path end |
#request_path=(path) ⇒ Object
112 113 114 |
# File 'lib/mascot.rb', line 112 def request_path=(path) @request_path = Pathname.new(path) end |
Instance Method Details
#find_by_request_path(request_path) ⇒ Object
Find the page with a path.
103 104 105 106 |
# File 'lib/mascot.rb', line 103 def find_by_request_path(request_path) return if request_path.nil? resources.find { |r| r.request_path == File.join("/", request_path) } end |
#resources(glob = DEFAULT_GLOB) ⇒ Object
Lazy stream of resources.
96 97 98 99 100 |
# File 'lib/mascot.rb', line 96 def resources(glob = DEFAULT_GLOB) Dir[validate_path(@file_path.join(glob))].select(&File.method(:file?)).lazy.map do |path| Resource.new request_path: request_path(path), file_path: path end end |