Sha256: 88821bfad0e15a2f01196c0ab19dab1f70f5c71795222d09a7a540e346db065e
Contents?: true
Size: 1.52 KB
Versions: 1
Compression:
Stored size: 1.52 KB
Contents
class Pathname # Checks that the file or directory indicated by the Pathname exists, # and returns the Pathname unmodified. If the Pathname fails this # check, an exception is raised. # # @example # Pathname.new(__FILE__).assert_exist! # == Pathname.new(__FILE__) # Pathname.new("/dev/null/nope").assert_exist! # == raises exception # # @param name [String, Symbol] # optional name to include in the error message # @return [self] # @raise [MiniSanity::Error] # if the file or directory indicated by the Pathname does not exist def assert_exist!(name = nil) unless self.exist? descriptor = name ? "#{name} (#{self})" : self.to_s raise MiniSanity::Error.new("#{descriptor} does not exist") end self end # Checks that the file or directory indicated by the Pathname does # not already exist, and returns the Pathname unmodified. If the # Pathname fails this check, an exception is raised. # # @example # Pathname.new("/dev/null/nope").refute_exist! # == Pathname.new("/dev/null/nope") # Pathname.new(__FILE__).refute_exist! # raises exception # # @param name [String, Symbol] # optional name to include in the error message # @return [self] # @raise [MiniSanity::Error] # if the file or directory indicated by the Pathname already exists def refute_exist!(name = nil) if self.exist? descriptor = name ? "#{name} (#{self})" : self.to_s raise MiniSanity::Error.new("#{descriptor} already exists") end self end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mini_sanity-1.0.0 | lib/mini_sanity/pathname.rb |