class QB::Path
An extension of {Pathname} that implements the facts we want about paths as {NRSER::Meta::Props}.
Public Class Methods
new(arg)
click to toggle source
@overload initialize path
Initialize in the same way as you would a {Pathname}. {#cwd} is set to the current directory (via {Pathname#getwd}) and the `path` argument is assigned to {#raw}. @param [String | Pathname] path Target path.
@overload initialize **values
Initialize by invoking {NRSER::Meta::Props#initialize_props}. The {#raw} value is passed up to {Pathname#initialize}. {#cwd} is accepted in `values`, allowing a re-instantiated object to "make sense" when the process' current directory may no longer be the one that data was constructed against. {#cwd} defaults to the current directory (via {Pathname.getwd}) if not provided.
@param **values see {NRSER::Meta::Props#initialize_props}
Calls superclass method
# File lib/qb/path.rb, line 177 def initialize arg case arg when Hash super arg[:raw] initialize_props cwd: Pathname.getwd, **arg else super arg initialize_props raw: arg, cwd: Pathname.getwd end end
Public Instance Methods
cwd?()
click to toggle source
@return [Boolean]
`true` if `self` is equal to {#cwd}.
# File lib/qb/path.rb, line 203 def cwd? self == cwd end
expanded?()
click to toggle source
@return [Boolean]
`true` if `self` is equal to {#expand_path}.
# File lib/qb/path.rb, line 195 def expanded? self == expand_path end
gem()
click to toggle source
# File lib/qb/path.rb, line 284 def gem unless instance_variable_defined? :@gem @gem = QB::Package::Gem.from_root_path path, repo: git end @gem end
git()
click to toggle source
{QB::Repo::Git} resource for the Git repo {#path} is in one, or {nil} if it isn't.
@return [QB::Repo::Git]
If {#path} is in a Git repo.
@return [nil]
If {#path} is not in a Git repo.
# File lib/qb/path.rb, line 275 def git unless instance_variable_defined? :@git @git = QB::Repo::Git.from_path path end @git end
path()
click to toggle source
@return [Pathname]
A regular (non-{QB::Path}) {Pathname} version of `self`.
# File lib/qb/path.rb, line 256 def path Pathname.new self end
Also aliased as: pathname
realpath?()
click to toggle source
Is `self` already it's real path?
@return [Boolean]
`true` if `self` and {#try_realpath} are equal.
# File lib/qb/path.rb, line 249 def realpath? self == try_realpath end
relative()
click to toggle source
Relative path from {#cwd} to `self`, if one exists.
@return [QB::Path]
If a relative path from {#cwd} to `self` exists.
@return [nil]
If no relative path from {#cwd} to `self` exists. Can't recall exactly how this happens, but I guess it can...
# File lib/qb/path.rb, line 217 def relative begin relative_path_from cwd rescue ArgumentError => error nil end end
try_realpath()
click to toggle source
Like {Pathname#realpath} but returns {nil} instead of raising if there isn't one.
@return [nil]
If there is no real path.
@return [Pathname]
If there is a real path.
# File lib/qb/path.rb, line 235 def try_realpath begin realpath rescue SystemCallError => error nil end end