Class: Pathname
- Defined in:
- lib/eac_ruby_utils/patches/pathname/if_exist.rb,
lib/eac_ruby_utils/patches/pathname/mkpath_s.rb,
lib/eac_ruby_utils/patches/pathname/parent_n.rb,
lib/eac_ruby_utils/patches/pathname/readlink_r.rb,
lib/eac_ruby_utils/patches/pathname/reqdir_glob.rb,
lib/eac_ruby_utils/patches/pathname/basename_sub.rb,
lib/eac_ruby_utils/patches/pathname/basename_noext.rb
Direct Known Subclasses
EacRubyUtils::Fs::ClearableDirectory, EacRubyUtils::Fs::Temp::File
Instance Method Summary collapse
- #basename_noext(limit = 1) ⇒ Object
- #basename_sub(suffix = '') ⇒ Object
- #if_exist(default_value = nil) ⇒ Object
-
#mkpath_s ⇒ Pathname
Execute .mkpath and return
self
. -
#parent_n(n) ⇒ Pathname
Apply .parent n times.
- #readlink_r ⇒ Object
-
#reqdir_glob(*args) ⇒ Pathname
A .glob that raises a ::RuntimeError if
self
is not a directory.
Instance Method Details
#basename_noext(limit = 1) ⇒ Object
7 8 9 |
# File 'lib/eac_ruby_utils/patches/pathname/basename_noext.rb', line 7 def basename_noext(limit = 1) basename(::EacRubyUtils::Fs.extname(basename.to_path, limit)) end |
#basename_sub(suffix = '') ⇒ Object
6 7 8 |
# File 'lib/eac_ruby_utils/patches/pathname/basename_sub.rb', line 6 def basename_sub(suffix = '') parent.join(yield(basename(suffix))) end |
#if_exist(default_value = nil) ⇒ Object
5 6 7 8 9 |
# File 'lib/eac_ruby_utils/patches/pathname/if_exist.rb', line 5 def if_exist(default_value = nil) return default_value unless exist? block_given? ? yield(self) : self end |
#mkpath_s ⇒ Pathname
Execute .mkpath and return self
.
8 9 10 11 |
# File 'lib/eac_ruby_utils/patches/pathname/mkpath_s.rb', line 8 def mkpath_s mkpath self end |
#parent_n(n) ⇒ Pathname
Apply .parent n times.
8 9 10 |
# File 'lib/eac_ruby_utils/patches/pathname/parent_n.rb', line 8 def parent_n(n) # rubocop:disable Naming/MethodParameterName n.times.inject(self) { |a, _e| a.parent } end |
#readlink_r ⇒ Object
6 7 8 9 10 |
# File 'lib/eac_ruby_utils/patches/pathname/readlink_r.rb', line 6 def readlink_r r = self r = r.readlink while r.symlink? r end |
#reqdir_glob(*args) ⇒ Pathname
A .glob that raises a ::RuntimeError if self
is not a directory.
8 9 10 11 12 |
# File 'lib/eac_ruby_utils/patches/pathname/reqdir_glob.rb', line 8 def reqdir_glob(*args) raise ::RuntimeError, "\"#{self}\" is not a directory" unless directory? glob(*args) end |