Class: QB::Path
- Inherits:
-
Pathname
- Object
- Pathname
- QB::Path
- Includes:
- NRSER::Meta::Props
- 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
trueifselfis equal to #cwd. -
#expanded? ⇒ Boolean
trueifselfis 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
selfalready 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.
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/qb/path.rb', line 176 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.
202 203 204 |
# File 'lib/qb/path.rb', line 202 def cwd? self == cwd end |
#expanded? ⇒ Boolean
Returns true if self is equal to #expand_path.
194 195 196 |
# File 'lib/qb/path.rb', line 194 def self == end |
#gem ⇒ Object
283 284 285 286 287 288 289 |
# File 'lib/qb/path.rb', line 283 def gem unless instance_variable_defined? :@gem @gem = QB::Package::Gem.from_root_path path, repo: git end @gem end |
#git ⇒ QB::Repo::Git?
274 275 276 277 278 279 280 |
# File 'lib/qb/path.rb', line 274 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.
255 256 257 |
# File 'lib/qb/path.rb', line 255 def path Pathname.new self end |
#realpath? ⇒ Boolean
Is self already it's real path?
248 249 250 |
# File 'lib/qb/path.rb', line 248 def realpath? self == try_realpath end |
#relative ⇒ QB::Path?
Relative path from #cwd to self, if one exists.
216 217 218 219 220 221 222 |
# File 'lib/qb/path.rb', line 216 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.
234 235 236 237 238 239 240 |
# File 'lib/qb/path.rb', line 234 def try_realpath begin realpath rescue SystemCallError => error nil end end |