Sha256: a69fae9380118d11166107ae13efd91828c80232332bcd8969cfb3dcc4d6bf95

Contents?: true

Size: 848 Bytes

Versions: 1

Compression:

Stored size: 848 Bytes

Contents

class Pathname
  # same as `#exist?`
  def exists?(*args) exist?(*args) ; end

  # @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)
  def mkparent
    dirname.mkpath
    return self
  end

  #
  # 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] Force creation of the file
  #
  # @returns the path itself (not the file)
  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

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gorillib-0.5.0 lib/gorillib/pathname/utils.rb