Sha256: a2fa0a3eebc6ca988f58eae72c3f3a79d0606debe1678700e5d5f4e553e96c13

Contents?: true

Size: 864 Bytes

Versions: 2

Compression:

Stored size: 864 Bytes

Contents

module Quickl
  class Command
    module Robustness
      include Naming
      
      # Checks that a command whose name is given exists
      # or raises a NoSuchCommand.
      def has_command!(name, referer = self.class)
        unless cmd = referer.subcommand_by_name(name)
          raise NoSuchCommand, "No such command #{name}" 
        end
        cmd
      end
      
      # Checks that _file_ is a readable file or raises an error.
      # Returns _file_ on success.
      def valid_read_file!(file, error_class = nil, msg = nil)
        if File.file?(file) and File.readable?(file)
          file
        else
          error_class ||= Quickl::IOAccessError
          msg ||= "Not a file or not readable: #{file}"
          raise error_class, msg, caller
        end
      end
      
    end # module Robustness
  end # class Command
end # module Quickl

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
quickl-0.2.2 lib/quickl/command/robustness.rb
quickl-0.2.1 lib/quickl/command/robustness.rb