Class: SearchPath

Inherits:
Object
  • Object
show all
Defined in:
lib/caphir/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

Constructor Details

#initializeSearchPath

Returns a new instance of SearchPath.



10
11
12
13
# File 'lib/caphir/searchpath.rb', line 10

def initialize
	@paths = []
	@next_path = {}
end

Class Method Details

.check(p) ⇒ Object



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

def SearchPath.check(p)
	raise "invalid search path: #{p}" unless File.directory?(p)
end

Instance Method Details

#<<(path) ⇒ Object



18
19
20
21
# File 'lib/caphir/searchpath.rb', line 18

def <<(path)
	SearchPath.check(path)
	@paths << path
end

#dupObject



37
38
39
40
41
42
43
# File 'lib/caphir/searchpath.rb', line 37

def dup
	d = SearchPath.new
	@paths.each do |p|
		d << p
	end
	d
end

#find(file) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
# File 'lib/caphir/searchpath.rb', line 23

def find(file)
	raise ArgumentError, "'#{file}' not found" \
		unless f = self.find_in(@paths, file)
	f
end

#find_next(file) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/caphir/searchpath.rb', line 28

def find_next(file)
	if next_paths = @next_path[file]
		f = self.find_in(next_paths, file)
		return f if f
	end
	# start the search over
	self.find(file)
end

#unshift(path) ⇒ Object



14
15
16
17
# File 'lib/caphir/searchpath.rb', line 14

def unshift(path)
	SearchPath.check(path)
	@paths.unshift(path)
end