Class: Pathname
- Defined in:
- lib/eac_ruby_utils/patches/pathname/child_of.rb,
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/assert_parent.rb,
lib/eac_ruby_utils/patches/pathname/basename_noext.rb
Direct Known Subclasses
EacRubyUtils::Fs::ClearableDirectory, EacRubyUtils::Fs::Temp::File
Instance Method Summary collapse
-
#assert_parent ⇒ self
Invoke
mkpath
for parent path and returnself
. - #basename_noext(limit = 1) ⇒ Object
- #basename_sub(suffix = '') ⇒ Pathname
-
#child_of?(parent_path) ⇒ Boolean
Indicate if
self
is child ofparent_path
. - #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
#assert_parent ⇒ self
Invoke mkpath
for parent path and return self
.
8 9 10 11 |
# File 'lib/eac_ruby_utils/patches/pathname/assert_parent.rb', line 8 def assert_parent parent.mkpath self end |
#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 = '') ⇒ Pathname
8 9 10 11 12 |
# File 'lib/eac_ruby_utils/patches/pathname/basename_sub.rb', line 8 def basename_sub(suffix = '') new_basename = basename(suffix) new_basename = yield(new_basename) if block_given? parent.join(new_basename) end |
#child_of?(parent_path) ⇒ Boolean
Indicate if self
is child of parent_path
.
9 10 11 12 13 14 15 |
# File 'lib/eac_ruby_utils/patches/pathname/child_of.rb', line 9 def child_of?(parent_path) self_parts = .each_filename.to_a parent_parts = parent_path..each_filename.to_a return false if self_parts == parent_parts parent_parts.zip(self_parts).all? { |x, y| x == y } 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 "\"#{self}\" is not a directory" unless directory? glob(*args) end |