module DirectoryWatcher::Paths
Paths contains helpful methods to determine paths of files inside the DirectoryWatcher library
Public Instance Methods
lib_path(*args,&block)
click to toggle source
Return a path relative to the 'lib' directory in this project
# File lib/directory_watcher/paths.rb, line 20 def lib_path(*args,&block) sub_path('lib', *args, &block) end
path(*args,&block)
click to toggle source
Return a path relative to the 'root' directory in the project
# File lib/directory_watcher/paths.rb, line 26 def path(*args,&block) sub_path('', *args, &block) end
root_dir()
click to toggle source
The root directory of the project is considered the parent directory of the 'lib' directory.
Returns The full expanded path of the parent directory of 'lib' going up the path from the current file. Trailing File::SEPARATOR is guaranteed
# File lib/directory_watcher/paths.rb, line 12 def root_dir path_parts = ::File.expand_path(__FILE__).split(::File::SEPARATOR) lib_index = path_parts.rindex("lib") return path_parts[0...lib_index].join(::File::SEPARATOR) + ::File::SEPARATOR end
sub_path(sub,*args,&block)
click to toggle source
Calculate the full expanded path of the item with respect to a sub path of 'root_dir'
# File lib/directory_watcher/paths.rb, line 33 def sub_path(sub,*args,&block) rv = ::File.join(root_dir, sub) + ::File::SEPARATOR rv = ::File.join(rv, *args) if args if block with_load_path( rv ) do rv = block.call end end return rv end
with_load_path(path, &block)
click to toggle source
Execute a block in the context of a path added to $LOAD_PATH
# File lib/directory_watcher/paths.rb, line 46 def with_load_path(path, &block) $LOAD_PATH.unshift path block.call ensure $LOAD_PATH.shift end