Exception: Quickl::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/quickl/errors.rb

Overview

Main class of all Quickl’s errors.

Quickl’s errors normally occur only in the context of a command execution, command which can be obtained through the dedicated accessor.

Each Quickl error comes bundled with a default reaction implemented by the react! method. Unless you provide your own reaction via dedicated Command’s DSL methods (react_to, no_react_to, …), this reaction will be executed if the error is raised. Default reactions are implemented so that the command fail gracefully for the ordinary commandline user.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Error

Creates an Exit instance



26
27
28
29
# File 'lib/quickl/errors.rb', line 26

def initialize(*args)
  super(args.find{|s| s.is_a?(String)} || "")
  @exit_code = args.find{|s| s.is_a?(Integer)} || nil
end

Instance Attribute Details

#commandObject

Quickl command under execution



20
21
22
# File 'lib/quickl/errors.rb', line 20

def command
  @command
end

#exit_codeObject (readonly)

Exit code



23
24
25
# File 'lib/quickl/errors.rb', line 23

def exit_code
  @exit_code
end

Instance Method Details

#do_kernel_exitObject

Print error’s message on IO returned by error_io and make a call to Kernel.exit with required exit code.



43
44
45
46
# File 'lib/quickl/errors.rb', line 43

def do_kernel_exit
  error_io.puts self.message
  Kernel.exit(exit_code) if exit?
end

#error_ioObject

Returns $stdout or $stderr according to exit code.



37
38
39
# File 'lib/quickl/errors.rb', line 37

def error_io
  exit_code == -1 ? $stderr : $stdout
end

#exit?Boolean

Returns true if exit code is not nil

Returns:

  • (Boolean)


32
33
34
# File 'lib/quickl/errors.rb', line 32

def exit?
  !exit_code.nil?
end