Module: Quickl::Command::Robustness

Includes:
Naming
Defined in:
lib/quickl/command/robustness.rb

Instance Method Summary collapse

Methods included from Naming

#command2module, #module2command

Instance Method Details

#has_command!(name, referer = self.class) ⇒ Object

Checks that a command whose name is given exists or raises a NoSuchCommand.



8
9
10
11
12
13
14
# File 'lib/quickl/command/robustness.rb', line 8

def has_command!(name, referer = self.class)
  name.split(':').inject(referer){|cur,look|
    cur.const_get(command2module(look))
  }
rescue NameError => ex
  raise NoSuchCommand, "No such command #{name}", ex.backtrace
end

#valid_read_file!(file, error_class = nil, msg = nil) ⇒ Object

Checks that file is a readable file or raises an error. Returns file on success.



18
19
20
21
22
23
24
25
26
# File 'lib/quickl/command/robustness.rb', line 18

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