Module: Doh
- Extended by:
- Doh
- Included in:
- Doh
- Defined in:
- lib/dohroot.rb,
lib/dohroot/findup.rb,
lib/dohroot/options.rb
Defined Under Namespace
Classes: DohRootNotFoundException, Options
Instance Method Summary
collapse
Instance Method Details
#find_root(start_directory, filename = 'dohroot', max_tries = 20) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/dohroot.rb', line 19
def find_root(start_directory, filename = 'dohroot', max_tries = 20)
rootfile = Doh.findup(start_directory, filename, max_tries)
if rootfile
Doh.root = File.dirname(rootfile)
end
end
|
#find_root_from_file(filepath = nil) ⇒ Object
26
27
28
|
# File 'lib/dohroot.rb', line 26
def find_root_from_file(filepath = nil)
Doh.find_root(File.dirname(filepath || caller[0]))
end
|
#find_root_from_path(path) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/dohroot.rb', line 30
def find_root_from_path(path)
if File.directory?(path)
Doh.find_root(path)
else
Doh.find_root(File.dirname(path))
end
end
|
#find_root_from_prog ⇒ Object
38
39
40
|
# File 'lib/dohroot.rb', line 38
def find_root_from_prog
Doh.find_root(File.dirname($PROGRAM_NAME))
end
|
#find_root_from_pwd ⇒ Object
42
43
44
|
# File 'lib/dohroot.rb', line 42
def find_root_from_pwd
Doh.find_root(Dir.pwd)
end
|
#findup(start_directory, filename, max_tries = 20) ⇒ Object
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/dohroot/findup.rb', line 4
def findup(start_directory, filename, max_tries = 20)
curr_directory = start_directory
max_tries.times do
path = File.expand_path(File.join(curr_directory, filename))
return path if File.exist?(path)
return nil if (path == '/')
curr_directory = File.join(curr_directory, '..')
end
nil
end
|
#root ⇒ Object
9
10
11
|
# File 'lib/dohroot.rb', line 9
def root
@root
end
|
#root=(directory) ⇒ Object
13
14
15
16
17
|
# File 'lib/dohroot.rb', line 13
def root=(directory)
@root = directory
libdir = File.join(@root, 'lib')
$LOAD_PATH.push(libdir) if libdir
end
|