class Pathname

Public Class Methods

receive(obj) click to toggle source
# File lib/gorillib/pathname.rb, line 89
def self.receive(obj)
  return obj if obj.nil?
  obj.is_a?(self) ? obj : new(obj)
end

Public Instance Methods

corename() click to toggle source

@return the basename without extension (using self.extname as the extension)

# File lib/gorillib/pathname.rb, line 95
def corename
  basename(self.extname)
end
exists?(*args) click to toggle source

same as ‘#exist?`

# File lib/gorillib/pathname/utils.rb, line 3
def exists?(*args) exist?(*args) ; end
find_all() click to toggle source

Like find, but returns an enumerable

# File lib/gorillib/pathname/utils.rb, line 19
def find_all
  Enumerator.new{|yielder| find{|path| yielder << path } }
end
if_missing(options={}, &block) click to toggle source

Executes the block (passing the opened file) if the file does not exist. Ignores the block otherwise. The block is required.

@param options @option options Force creation of the file

@returns the path itself (not the file)

# File lib/gorillib/pathname/utils.rb, line 31
def if_missing(options={}, &block)
  ArgumentError.block_required!(block)
  return self if exist? && (not options[:force])
  #
  mkparent
  open((options[:mode] || 'w'), &block)
  return self
end
inspect_compact() click to toggle source

@return [String] compact string rendering

# File lib/gorillib/pathname.rb, line 100
def inspect_compact() to_path.dump ; end
mkparent() click to toggle source

@example It chains nicely:

# put each file in eg. dest/f/foo.json
Pathname.of(:dest, slug[0..0], "#{slug}.json").mkparent.open('w') do |file|
  # ...
end

@returns the path itself (not its parent)

# File lib/gorillib/pathname/utils.rb, line 12
def mkparent
  dirname.mkpath
  return self
end