class Dry::View::Path
@api private
Attributes
dir[R]
root[R]
Public Class Methods
[](path)
click to toggle source
# File lib/dry/view/path.rb, line 15 def self.[](path) if path.is_a?(self) path else new(path) end end
new(dir, root: dir)
click to toggle source
# File lib/dry/view/path.rb, line 23 def initialize(dir, root: dir) @dir = Pathname(dir) @root = Pathname(root) end
Public Instance Methods
chdir(dirname)
click to toggle source
# File lib/dry/view/path.rb, line 36 def chdir(dirname) self.class.new(dir.join(dirname), root: root) end
lookup(name, format, child_dirs: [], parent_dir: false)
click to toggle source
# File lib/dry/view/path.rb, line 28 def lookup(name, format, child_dirs: [], parent_dir: false) fetch_or_store(dir, root, name, format, child_dirs, parent_dir) do lookup_template(name, format) || lookup_in_child_dirs(name, format, child_dirs: child_dirs) || parent_dir && lookup_in_parent_dir(name, format, child_dirs: child_dirs) end end
to_s()
click to toggle source
# File lib/dry/view/path.rb, line 40 def to_s dir.to_s end
Private Instance Methods
lookup_in_child_dirs(name, format, child_dirs:)
click to toggle source
# File lib/dry/view/path.rb, line 56 def lookup_in_child_dirs(name, format, child_dirs:) child_dirs.reduce(nil) { |_, dir| template = chdir(dir).lookup(name, format) break template if template } end
lookup_in_parent_dir(name, format, child_dirs:)
click to toggle source
# File lib/dry/view/path.rb, line 63 def lookup_in_parent_dir(name, format, child_dirs:) !root? && chdir("..").lookup(name, format, child_dirs: child_dirs, parent_dir: true) end
lookup_template(name, format)
click to toggle source
Search for a template using a wildcard for the engine extension
# File lib/dry/view/path.rb, line 51 def lookup_template(name, format) glob = dir.join("#{name}.#{format}.*") Dir[glob].first end
root?()
click to toggle source
# File lib/dry/view/path.rb, line 46 def root? dir == root end