Class: Hike::Paths

Inherits:
NormalizedArray show all
Defined in:
lib/hike/paths.rb

Overview

`Paths` is an internal collection for tracking path strings.

Instance Method Summary collapse

Methods inherited from NormalizedArray

#<<, #[]=, #collect!, #insert, #normalize_elements, #push, #replace, #unshift

Constructor Details

#initialize(root = ".") ⇒ Paths

Returns a new instance of Paths.


7
8
9
10
# File 'lib/hike/paths.rb', line 7

def initialize(root = ".")
  @root = Pathname.new(root)
  super()
end

Instance Method Details

#normalize_element(path) ⇒ Object

Relative paths added to this array are expanded relative to `@root`.

paths = Paths.new("/usr/local")
paths << "tmp"
paths << "/tmp"

paths
# => ["/usr/local/tmp", "/tmp"]

21
22
23
24
25
# File 'lib/hike/paths.rb', line 21

def normalize_element(path)
  path = Pathname.new(path)
  path = @root.join(path) if path.relative?
  path.expand_path.to_s
end