Sha256: 5abec42cd3ae3db175b5545e9dae893c283f9dd2148eb32384d8923fe2ca22d7
Contents?: true
Size: 976 Bytes
Versions: 2
Compression:
Stored size: 976 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 # Like find, but returns an enumerable # def find_all Enumerator.new{|yielder| find{|path| yielder << path } } 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gorillib-0.6.0 | lib/gorillib/pathname/utils.rb |
gorillib-0.5.2 | lib/gorillib/pathname/utils.rb |