Module: Doh
- Extended by:
- Doh
- Included in:
- Doh
- Defined in:
- lib/dohroot/pkg.rb,
lib/dohroot/main.rb,
lib/dohroot/findup.rb,
lib/dohroot/options.rb
Defined Under Namespace
Classes: Options
Instance Method Summary collapse
- #find_root(start_directory, filename = 'dohroot', max_tries = 20) ⇒ Object
- #find_root_from_file(filepath = nil) ⇒ Object
- #find_root_from_path(path) ⇒ Object
- #find_root_from_prog ⇒ Object
- #find_root_from_pwd ⇒ Object
- #findup(start_directory, filename, max_tries = 20) ⇒ Object
- #root ⇒ Object
- #root=(directory) ⇒ Object
- #use_pkg(init_file, *name_list) ⇒ Object
Instance Method Details
#find_root(start_directory, filename = 'dohroot', max_tries = 20) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/dohroot/main.rb', line 16 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
23 24 25 |
# File 'lib/dohroot/main.rb', line 23 def find_root_from_file(filepath = nil) Doh.find_root(File.dirname(filepath || caller[0])) end |
#find_root_from_path(path) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/dohroot/main.rb', line 27 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
35 36 37 |
# File 'lib/dohroot/main.rb', line 35 def find_root_from_prog Doh.find_root(File.dirname($PROGRAM_NAME)) end |
#find_root_from_pwd ⇒ Object
39 40 41 |
# File 'lib/dohroot/main.rb', line 39 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.(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
6 7 8 |
# File 'lib/dohroot/main.rb', line 6 def root @root end |
#root=(directory) ⇒ Object
10 11 12 13 14 |
# File 'lib/dohroot/main.rb', line 10 def root=(directory) @root = directory libdir = File.join(@root, 'lib') $LOAD_PATH.push(libdir) if libdir && !$LOAD_PATH.include?(libdir) end |
#use_pkg(init_file, *name_list) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dohroot/pkg.rb', line 6 def use_pkg(init_file, *name_list) if name_list.empty? Dir.glob(File.join(Doh.root, 'pkg/*/')).each do |rootdir| name_list << File.basename(rootdir) end end @pkg_used ||= [] retval = false name_list.each do |name| next if @pkg_used.include?(name) retval = true @pkg_used << name use_one_pkg(init_file, name) end retval end |