Class: PathTo
- Inherits:
-
Object
- Object
- PathTo
- Defined in:
- lib/path_to.rb,
lib/path_to/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#paths ⇒ Object
Returns the value of attribute paths.
Instance Method Summary collapse
- #file(filename, opts = {}) ⇒ Object
-
#initialize(*paths) ⇒ PathTo
constructor
A new instance of PathTo.
- #path_to(filename) ⇒ Object
-
#paths_to(filenames = []) ⇒ Object
Plural version of path_to.
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
#paths ⇒ Object
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 |