module Doh

Public Instance Methods

find_root(start_directory, filename = 'dohroot', max_tries = 20) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/dohroot/main.rb, line 35
def find_root_from_prog
  Doh.find_root(File.dirname($PROGRAM_NAME))
end
find_root_from_pwd() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/dohroot/main.rb, line 6
def root
  @root
end
root=(directory) click to toggle source
# 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