Class: Mascot::Sitemap

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(file_path: DEFAULT_ROOT_DIR, request_path: DEFAULT_ROOT_REQUEST_PATH) ⇒ Sitemap

Returns a new instance of Sitemap.



95
96
97
98
# File 'lib/mascot.rb', line 95

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_pathObject

Returns the value of attribute file_path.



93
94
95
# File 'lib/mascot.rb', line 93

def file_path
  @file_path
end

#request_path=(path) ⇒ Object



117
118
119
# File 'lib/mascot.rb', line 117

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.



108
109
110
111
# File 'lib/mascot.rb', line 108

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.



101
102
103
104
105
# File 'lib/mascot.rb', line 101

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