Class: SearchPath
Instance Method Summary collapse
- #add(new_path) ⇒ Object
- #each ⇒ Object
-
#initialize(path) ⇒ SearchPath
constructor
A new instance of SearchPath.
- #join ⇒ Object (also: #to_s)
- #regex(string) ⇒ Object
- #remove(old_path) ⇒ Object
- #replace(old_path, new_path) ⇒ Object
- #replace_or_add(old_path, new_path) ⇒ Object
- #to_bash ⇒ Object
Methods included from Enumerable
Constructor Details
#initialize(path) ⇒ SearchPath
Returns a new instance of SearchPath.
6 7 8 |
# File 'lib/pik/search_path.rb', line 6 def initialize(path) @path = path.to_s.split(';').reject{|i| i.empty? } end |
Instance Method Details
#add(new_path) ⇒ Object
35 36 37 38 39 |
# File 'lib/pik/search_path.rb', line 35 def add(new_path) new_path = Pathname(new_path) @path.unshift new_path.to_windows.to_s self end |
#each ⇒ Object
31 32 33 |
# File 'lib/pik/search_path.rb', line 31 def each @path.each{|path| yield path } end |
#join ⇒ Object Also known as: to_s
55 56 57 |
# File 'lib/pik/search_path.rb', line 55 def join @path.join(';') end |
#regex(string) ⇒ Object
64 65 66 |
# File 'lib/pik/search_path.rb', line 64 def regex(string) Regexp.new(Regexp.escape(string.to_s), true) end |
#remove(old_path) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/pik/search_path.rb', line 10 def remove(old_path) old = Pathname(old_path). @path = @path.reject{|dir| Pathname(dir) == old } @path = @path.uniq self end |
#replace(old_path, new_path) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pik/search_path.rb', line 17 def replace(old_path, new_path) old_path = Pathname(old_path) new_path = Pathname(new_path) @path.map!{|dir| if Pathname(dir) == old_path new_path.to_windows.to_s else dir end } @path = @path.uniq.compact self end |
#replace_or_add(old_path, new_path) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pik/search_path.rb', line 41 def replace_or_add(old_path, new_path) if old_path.nil? add(new_path) return self end old_path = Pathname(old_path) new_path = Pathname(new_path) return self if old_path == new_path old_search_path = @path.dup replace(old_path, new_path) add(new_path) if @path == old_search_path self end |