Class: Hike::Trail

Inherits:
Object
  • Object
show all
Defined in:
lib/hike/trail.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = ".") ⇒ Trail

Returns a new instance of Trail.



5
6
7
8
9
10
# File 'lib/hike/trail.rb', line 5

def initialize(root = ".")
  @root = File.expand_path(root)
  @index = DirectoryIndex.new
  @paths = Paths.new(@root)
  @extensions = Extensions.new
end

Instance Attribute Details

#extensionsObject (readonly)

Returns the value of attribute extensions.



3
4
5
# File 'lib/hike/trail.rb', line 3

def extensions
  @extensions
end

#pathsObject (readonly)

Returns the value of attribute paths.



3
4
5
# File 'lib/hike/trail.rb', line 3

def paths
  @paths
end

#rootObject (readonly)

Returns the value of attribute root.



3
4
5
# File 'lib/hike/trail.rb', line 3

def root
  @root
end

Instance Method Details

#find(*logical_paths, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hike/trail.rb', line 12

def find(*logical_paths, &block)
  if block_given?
    options = extract_options!(logical_paths)
    base_path = options[:base_path] || root
    reset!

    logical_paths.each do |logical_path|
      if relative?(logical_path)
        find_in_base_path(logical_path, base_path, &block)
      else
        find_in_paths(logical_path, &block)
      end
    end

    nil
  else
    find(*logical_paths) do |path|
      return path
    end
  end
end