Module: Gorillib::Pathref
Constant Summary collapse
- ROOT_PATHS =
Hash.new
Instance Method Summary collapse
-
#of(*pathsegs) ⇒ Pathname
(also: #path_to)
Expand a path with late-evaluated segments.
- #register_default_paths(handle_paths = {}) ⇒ Object
- #register_path(handle, *pathsegs) ⇒ Object
- #register_paths(handle_paths = {}) ⇒ Object
-
#relpath_to(*pathsegs) ⇒ Object
(also: #relative_path_to)
Expand a path with late-evaluated segments Calls cleanpath (removing
//
double slashes and useless..
s), but does not reference the filesystem or make paths absolute. - #unregister_path(handle) ⇒ Object
Instance Method Details
#of(*pathsegs) ⇒ Pathname Also known as: path_to
Expand a path with late-evaluated segments. Calls expand_path -- '~' becomes $HOME, '..' is expanded, etc.
55 56 57 |
# File 'lib/gorillib/pathname.rb', line 55 def of(*pathsegs) relpath_to(*pathsegs). end |
#register_default_paths(handle_paths = {}) ⇒ Object
19 20 21 22 23 |
# File 'lib/gorillib/pathname.rb', line 19 def register_default_paths(handle_paths = {}) handle_paths.each_pair do |handle, pathsegs| register_path(handle, *pathsegs) unless ROOT_PATHS.has_key?(handle.to_sym) end end |
#register_path(handle, *pathsegs) ⇒ Object
10 11 12 13 |
# File 'lib/gorillib/pathname.rb', line 10 def register_path(handle, *pathsegs) ArgumentError.arity_at_least!(pathsegs, 1) ROOT_PATHS[handle.to_sym] = pathsegs end |
#register_paths(handle_paths = {}) ⇒ Object
15 16 17 |
# File 'lib/gorillib/pathname.rb', line 15 def register_paths(handle_paths = {}) handle_paths.each_pair{|handle, pathsegs| register_path(handle, *pathsegs) } end |
#relpath_to(*pathsegs) ⇒ Object Also known as: relative_path_to
Expand a path with late-evaluated segments
Calls cleanpath (removing //
double slashes and useless ..
s), but does
not reference the filesystem or make paths absolute
67 68 69 70 71 |
# File 'lib/gorillib/pathname.rb', line 67 def relpath_to(*pathsegs) ArgumentError.arity_at_least!(pathsegs, 1) pathsegs = pathsegs.map{|ps| (ps) }.flatten self.new(File.join(*pathsegs)).cleanpath(true) end |
#unregister_path(handle) ⇒ Object
25 26 27 |
# File 'lib/gorillib/pathname.rb', line 25 def unregister_path(handle) ROOT_PATHS.delete handle.to_sym end |