class Opal::Hike::Trail
‘Trail` is the public container class for holding paths and extensions.
def append_extensions(*extensions)
def append_extensions(*extensions) @extensions.concat(extensions.map { |e| normalize_extension(e) }) end
def append_paths(*paths)
def append_paths(*paths) @paths.concat(paths.map { |p| normalize_path(p) }) end
def entries(path)
recommend to use this method for general purposes. It exists for
`Trail#entries` is equivalent to `Dir#entries`. It is not
def entries(path) pathname = Pathname.new(path) if pathname.directory? pathname.entries.reject { |entry| entry.to_s =~ /^\.|~$|^\#.*\#$/ }.sort else [] end end
def find(*args, &block)
# => "~/Projects/hike/test/test_trail.rb"
trail.find "test_trail"
# => "~/Projects/hike/lib/hike/trail.rb"
trail.find "hike/trail"
trail.paths.push "lib", "test"
trail.extensions.push ".rb"
trail = Hike::Trail.new "~/Projects/hike"
path collection.
`Trail#find` returns a the expand path for a logical path in the
def find(*args, &block) index.find(*args, &block) end
def index
index.find "test_trail"
index.find "hike/trail"
index = trail.index
searching, `index` will avoid excess system calls.
confident that you are not making changes the paths you are
does not update when the file system changes. If you are
interface as `Trail`. An `Index` is a cached `Trail` object that
`Trail#index` returns an `Index` object that has the same
def index Index.new(root, paths, extensions) end
def initialize(root = '.')
current working directory. Any relative paths added to
A Trail accepts an optional root path that defaults to your
def initialize(root = '.') @root = Pathname.new(root).expand_path @paths = [] @extensions = [] end
def normalize_extension(ext)
def normalize_extension(ext) ext.start_with?('.') ? ext : ".#{ext}" end
def normalize_path(path)
def normalize_path(path) path = Pathname.new(path) path = @root.join(path) if path.relative? path.expand_path.to_s end
def root
def root @root.to_s end
def stat(path)
recommend to use this method for general purposes. It exists for
`Trail#stat` is equivalent to `File#stat`. It is not
def stat(path) if File.exist?(path) File.stat(path.to_s) else # nil end end