Class: QB::Path
- Inherits:
-
Pathname
- Object
- Pathname
- QB::Path
- Includes:
- NRSER::Props::Immutable::InstanceVariables
- Defined in:
- lib/qb/path.rb
Overview
An extension of Pathname that implements the facts we want about paths as NRSER::Meta::Props.
Instance Method Summary collapse
-
#cwd? ⇒ Boolean
true
ifself
is equal to #cwd. -
#expanded? ⇒ Boolean
true
ifself
is equal to #expand_path. - #gem ⇒ Object
- #git ⇒ QB::Repo::Git?
-
#initialize(arg) ⇒ Path
constructor
A new instance of Path.
-
#path ⇒ Pathname
(also: #pathname)
A regular (non-Path) Pathname version of
self
. -
#realpath? ⇒ Boolean
Is
self
already it's real path?. -
#relative ⇒ QB::Path?
Relative path from #cwd to
self
, if one exists. -
#try_realpath ⇒ nil, Pathname
Like Pathname#realpath but returns nil instead of raising if there isn't one.
Constructor Details
#initialize(path) ⇒ Path #initialize(**values) ⇒ Path
Returns a new instance of Path.
177 178 179 180 181 182 183 184 185 186 |
# 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 |
Instance Method Details
#cwd? ⇒ Boolean
Returns true
if self
is equal to #cwd.
203 204 205 |
# File 'lib/qb/path.rb', line 203 def cwd? self == cwd end |
#expanded? ⇒ Boolean
Returns true
if self
is equal to #expand_path.
195 196 197 |
# File 'lib/qb/path.rb', line 195 def self == end |
#gem ⇒ Object
284 285 286 287 288 289 290 |
# 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 ⇒ QB::Repo::Git?
275 276 277 278 279 280 281 |
# 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 ⇒ Pathname Also known as: pathname
Returns A regular (non-QB::Path) Pathname version of self
.
256 257 258 |
# File 'lib/qb/path.rb', line 256 def path Pathname.new self end |
#realpath? ⇒ Boolean
Is self
already it's real path?
249 250 251 |
# File 'lib/qb/path.rb', line 249 def realpath? self == try_realpath end |
#relative ⇒ QB::Path?
Relative path from #cwd to self
, if one exists.
217 218 219 220 221 222 223 |
# File 'lib/qb/path.rb', line 217 def relative begin relative_path_from cwd rescue ArgumentError => error nil end end |
#try_realpath ⇒ nil, Pathname
Like Pathname#realpath but returns nil instead of raising if there isn't one.
235 236 237 238 239 240 241 |
# File 'lib/qb/path.rb', line 235 def try_realpath begin realpath rescue SystemCallError => error nil end end |