class Sitepress::ResourceCollection

Represents a collection of resources. Provides interfaces to query resource via globbing, paths, etc.

Attributes

root_path[R]

Used by `#glob` to determine the full path when given a relative glob pattern.

Public Class Methods

new(node: , root_path: ".") click to toggle source
# File lib/sitepress/resource_collection.rb, line 14
def initialize(node: , root_path: ".")
  @node = node
  @root_path = Pathname.new(root_path)
end

Public Instance Methods

get(request_path) click to toggle source
# File lib/sitepress/resource_collection.rb, line 24
def get(request_path)
  @node.get(request_path)
end
glob(pattern) click to toggle source
# File lib/sitepress/resource_collection.rb, line 19
def glob(pattern)
  paths = Dir.glob root_path.join(pattern)
  resources.select { |r| paths.include? r.asset.path.to_s }
end

Private Instance Methods

resources() click to toggle source
# File lib/sitepress/resource_collection.rb, line 29
def resources
  @node.flatten
end