Class: PathTo

Inherits:
Object
  • Object
show all
Defined in:
lib/path_to.rb,
lib/path_to/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*paths) ⇒ PathTo

Returns a new instance of PathTo.



7
8
9
# File 'lib/path_to.rb', line 7

def initialize(*paths)
  @paths = Array(paths)
end

Instance Attribute Details

#pathsObject

Returns the value of attribute paths.



5
6
7
# File 'lib/path_to.rb', line 5

def paths
  @paths
end

Instance Method Details

#file(filename, opts = {}) ⇒ Object



26
27
28
29
# File 'lib/path_to.rb', line 26

def file(filename, opts={})
  mode, perm, opt = opts[:mode], opts[:perm], opts[:opt]
  File.new(path_to(filename), mode, perm, opt)
end

#path_to(filename) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/path_to.rb', line 11

def path_to(filename)
  paths.each do |path|
    fullpath = File.join(path, filename)
    if File.exists?(fullpath)
      return fullpath
    end
  end
  nil
end

#paths_to(filenames = []) ⇒ Object

Plural version of path_to



22
23
24
# File 'lib/path_to.rb', line 22

def paths_to(filenames=[])
  Array(filenames).map{ |filename| path_to(filename) }
end