Class: Sitepress::ResourceIndexer
- Inherits:
-
Object
- Object
- Sitepress::ResourceIndexer
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/sitepress/resource_indexer.rb
Overview
Flattens a tree of Sitepress::Node and Sitepress:Resource classes into a collection of resources that can be quickly globbed, queried, or accessed.
Instance Attribute Summary collapse
-
#root_path ⇒ Object
readonly
Used by ‘#glob` to determine the full path when given a relative glob pattern.
Instance Method Summary collapse
- #get(request_path) ⇒ Object
- #glob(pattern) ⇒ Object
-
#initialize(node:, root_path: ".") ⇒ ResourceIndexer
constructor
A new instance of ResourceIndexer.
Constructor Details
#initialize(node:, root_path: ".") ⇒ ResourceIndexer
Returns a new instance of ResourceIndexer.
14 15 16 17 |
# File 'lib/sitepress/resource_indexer.rb', line 14 def initialize(node: , root_path: ".") @node = node @root_path = Pathname.new(root_path) end |
Instance Attribute Details
#root_path ⇒ Object (readonly)
Used by ‘#glob` to determine the full path when given a relative glob pattern.
12 13 14 |
# File 'lib/sitepress/resource_indexer.rb', line 12 def root_path @root_path end |
Instance Method Details
#get(request_path) ⇒ Object
24 25 26 |
# File 'lib/sitepress/resource_indexer.rb', line 24 def get(request_path) @node.get(request_path) end |
#glob(pattern) ⇒ Object
19 20 21 22 |
# File 'lib/sitepress/resource_indexer.rb', line 19 def glob(pattern) paths = Dir.glob root_path.join(pattern) resources.select { |r| paths.include? r.asset.path.to_s } end |