Class: SearchPath
- Inherits:
-
Object
- Object
- SearchPath
- Defined in:
- lib/dbc/searchpath.rb
Overview
Copyright © 2004 Charles M Mills This document is licenced under The MIT Licence. THIS SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND. See included LICENCE file.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(path) ⇒ Object
- #add(path, check = true) ⇒ Object
- #check ⇒ Object
- #find(file) ⇒ Object
-
#initialize ⇒ SearchPath
constructor
A new instance of SearchPath.
- #unshift(path) ⇒ Object
Constructor Details
#initialize ⇒ SearchPath
Returns a new instance of SearchPath.
12 13 14 |
# File 'lib/dbc/searchpath.rb', line 12 def initialize @paths = [] end |
Class Method Details
.check(p) ⇒ Object
7 8 9 10 11 |
# File 'lib/dbc/searchpath.rb', line 7 def SearchPath.check(p) if !File.exists?(p) or !File.directory?(p) raise "invalid search path: #{p}" end end |
Instance Method Details
#<<(path) ⇒ Object
23 24 25 |
# File 'lib/dbc/searchpath.rb', line 23 def <<(path) self.add(path) end |
#add(path, check = true) ⇒ Object
15 16 17 18 |
# File 'lib/dbc/searchpath.rb', line 15 def add(path, check=true) SearchPath.check(path) @paths << path end |
#check ⇒ Object
27 28 29 30 31 |
# File 'lib/dbc/searchpath.rb', line 27 def check @paths.each do |p| SearchPath.check(p) end end |
#find(file) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/dbc/searchpath.rb', line 32 def find(file) dir = @paths.find do |inc_dir| File.exists?(File.join(inc_dir, file)) end raise ArgumentError, "'#{file}' not found" unless dir File.join(dir, file) end |
#unshift(path) ⇒ Object
19 20 21 22 |
# File 'lib/dbc/searchpath.rb', line 19 def unshift(path) SearchPath.check(path) @paths.unshift(path) end |