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
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.
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/qb/path.rb', line 174 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.
200 201 202 |
# File 'lib/qb/path.rb', line 200 def cwd? self == cwd end |
#expanded? ⇒ Boolean
Returns true if self is equal to #expand_path.
192 193 194 |
# File 'lib/qb/path.rb', line 192 def self == end |
#gem ⇒ Object
279 280 281 282 283 284 285 |
# File 'lib/qb/path.rb', line 279 def gem unless instance_variable_defined? :@gem @gem = QB::Package::Gem.from_root_path path end @gem end |
#git ⇒ QB::Repo::Git?
270 271 272 273 274 275 276 |
# File 'lib/qb/path.rb', line 270 def git unless instance_variable_defined? :@git @git = QB::Repo::Git.from_path path end @git end |
#path ⇒ Pathname
Returns A regular (non-QB::Path) Pathname version of self.
253 254 255 |
# File 'lib/qb/path.rb', line 253 def path Pathname.new self end |
#realpath? ⇒ Boolean
Is self already it's real path?
246 247 248 |
# File 'lib/qb/path.rb', line 246 def realpath? self == try_realpath end |
#relative ⇒ QB::Path?
Relative path from #cwd to self, if one exists.
214 215 216 217 218 219 220 |
# File 'lib/qb/path.rb', line 214 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.
232 233 234 235 236 237 238 |
# File 'lib/qb/path.rb', line 232 def try_realpath begin realpath rescue SystemCallError => error nil end end |