Parent

Class Index [+]

Quicksearch

Hike::Trail

`Trail` is the public container class for holding paths and extensions.

Attributes

paths[R]

`Trail#paths` is a mutable `Paths` collection.

    trail = Hike::Trail.new
    trail.paths.push "~/Projects/hike/lib", "~/Projects/hike/test"

The order of the paths is significant. Paths in the beginning of the collection will be checked first. In the example above, `~/Projects/hike/lib/hike.rb` would shadow the existent of `~/Projects/hike/test/hike.rb`.

extensions[R]

`Trail#extensions` is a mutable `Extensions` collection.

    trail = Hike::Trail.new
    trail.paths.push "~/Projects/hike/lib"
    trail.extensions.push ".rb"

Extensions allow you to find files by just their name omitting their extension. Is similar to Ruby’s require mechanism that allows you to require files with specifiying `foo.rb`.

aliases[R]

`Index#aliases` is a mutable `Hash` mapping an extension to an `Array` of aliases.

  trail = Hike::Trail.new
  trail.paths.push "~/Projects/hike/site"
  trail.aliases['.htm']   = 'html'
  trail.aliases['.xhtml'] = 'html'
  trail.aliases['.php']   = 'html'

Aliases provide a fallback when the primary extension is not matched. In the example above, a lookup for “foo.html“ will check for the existence of “foo.htm“, “foo.xhtml“, or “foo.php“.

Public Class Methods

new(root = ".") click to toggle source

A Trail accepts an optional root path that defaults to your current working directory. Any relative paths added to `Trail#paths` will expanded relative to the root.

    # File lib/hike/trail.rb, line 48
48:     def initialize(root = ".")
49:       @root       = Pathname.new(root).expand_path
50:       @paths      = Paths.new(@root)
51:       @extensions = Extensions.new
52:       @aliases    = Hash.new { |h, k| h[k] = Extensions.new }
53:     end

Public Instance Methods

alias_extension(new_extension, old_extension) click to toggle source

Alias `new_extension` to `old_extension`

    # File lib/hike/trail.rb, line 95
95:     def alias_extension(new_extension, old_extension)
96:       aliases[normalize_extension(new_extension)] = normalize_extension(old_extension)
97:     end
append_extension(*extensions) click to toggle source
Alias for: append_extensions
append_extensions(*extensions) click to toggle source

Append `extension` to `Extensions` collection

    # File lib/hike/trail.rb, line 84
84:     def append_extensions(*extensions)
85:       self.extensions.push(*extensions)
86:     end
Also aliased as: append_extension
append_path(*paths) click to toggle source
Alias for: append_paths
append_paths(*paths) click to toggle source

Append `path` to `Paths` collection

    # File lib/hike/trail.rb, line 67
67:     def append_paths(*paths)
68:       self.paths.push(*paths)
69:     end
Also aliased as: append_path
entries(*args) click to toggle source

`Trail#entries` is equivalent to `Dir#entries`. It is not recommend to use this method for general purposes. It exists for parity with `Index#entries`.

     # File lib/hike/trail.rb, line 159
159:     def entries(*args)
160:       index.entries(*args)
161:     end
find(*args, &block) click to toggle source

`Trail#find` returns a the expand path for a logical path in the path collection.

    trail = Hike::Trail.new "~/Projects/hike"
    trail.extensions.push ".rb"
    trail.paths.push "lib", "test"

    trail.find "hike/trail"
    # => "~/Projects/hike/lib/hike/trail.rb"

    trail.find "test_trail"
    # => "~/Projects/hike/test/test_trail.rb"

`find` accepts multiple fallback logical paths that returns the first match.

    trail.find "hike", "hike/index"

is equivalent to

    trail.find("hike") || trail.find("hike/index")

Though `find` always returns the first match, it is possible to iterate over all shadowed matches and fallbacks by supplying a block.

    trail.find("hike", "hike/index") { |path| warn path }

This allows you to filter your matches by any condition.

    trail.find("application") do |path|
      return path if mime_type_for(path) == "text/css"
    end
     # File lib/hike/trail.rb, line 138
138:     def find(*args, &block)
139:       index.find(*args, &block)
140:     end
index() click to toggle source

`Trail#index` returns an `Index` object that has the same interface as `Trail`. An `Index` is a cached `Trail` object that does not update when the file system changes. If you are confident that you are not making changes the paths you are searching, `index` will avoid excess system calls.

    index = trail.index
    index.find "hike/trail"
    index.find "test_trail"
     # File lib/hike/trail.rb, line 152
152:     def index
153:       Index.new(root, paths, extensions, aliases)
154:     end
prepend_extension(*extensions) click to toggle source
Alias for: prepend_extensions
prepend_extensions(*extensions) click to toggle source

Prepend `extension` to `Extensions` collection

    # File lib/hike/trail.rb, line 78
78:     def prepend_extensions(*extensions)
79:       self.extensions.unshift(*extensions)
80:     end
Also aliased as: prepend_extension
prepend_path(*paths) click to toggle source
Alias for: prepend_paths
prepend_paths(*paths) click to toggle source

Prepend `path` to `Paths` collection

    # File lib/hike/trail.rb, line 61
61:     def prepend_paths(*paths)
62:       self.paths.unshift(*paths)
63:     end
Also aliased as: prepend_path
remove_extension(extension) click to toggle source

Remove `extension` from `Extensions` collection

    # File lib/hike/trail.rb, line 90
90:     def remove_extension(extension)
91:       self.extensions.delete(extension)
92:     end
remove_path(path) click to toggle source

Remove `path` from `Paths` collection

    # File lib/hike/trail.rb, line 73
73:     def remove_path(path)
74:       self.paths.delete(path)
75:     end
root() click to toggle source

`Trail#root` returns root path as a `String`. This attribute is immutable.

    # File lib/hike/trail.rb, line 56
56:     def root
57:       @root.to_s
58:     end
stat(*args) click to toggle source

`Trail#stat` is equivalent to `File#stat`. It is not recommend to use this method for general purposes. It exists for parity with `Index#stat`.

     # File lib/hike/trail.rb, line 166
166:     def stat(*args)
167:       index.stat(*args)
168:     end
unalias_extension(extension) click to toggle source

Remove the alias for `extension`

     # File lib/hike/trail.rb, line 100
100:     def unalias_extension(extension)
101:       aliases.delete(normalize_extension(extension))
102:     end

Private Instance Methods

normalize_extension(extension) click to toggle source
     # File lib/hike/trail.rb, line 171
171:       def normalize_extension(extension)
172:         if extension[/^\./]
173:           extension
174:         else
175:           ".#{extension}"
176:         end
177:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.