File: paths.rb

package info (click to toggle)
ruby-hike 1.2.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 96 kB
  • sloc: ruby: 280; makefile: 2
file content (27 lines) | stat: -rw-r--r-- 650 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'pathname'
require 'hike/normalized_array'

module Hike
  # `Paths` is an internal collection for tracking path strings.
  class Paths < NormalizedArray
    def initialize(root = ".")
      @root = Pathname.new(root)
      super()
    end

    # 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"]
    #
    def normalize_element(path)
      path = Pathname.new(path)
      path = @root.join(path) if path.relative?
      path.expand_path.to_s
    end
  end
end