Class: Pathname

Inherits:
Object show all
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

Instance Method Summary collapse

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_sPathname

Execute .mkpath and return self.

Returns:



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.

Returns:



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


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.

Returns:

Raises:

  • (::RuntimeError)


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