Exception: Quickl::Error
- 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.
Direct Known Subclasses
Exit, Help, IOAccessError, InvalidArgument, InvalidOption, NoSuchCommand
Instance Attribute Summary collapse
-
#command ⇒ Object
Quickl command under execution.
-
#exit_code ⇒ Object
readonly
Exit code.
Instance Method Summary collapse
-
#do_kernel_exit ⇒ Object
Print error’s message on IO returned by error_io and make a call to Kernel.exit with required exit code.
-
#error_io ⇒ Object
Returns $stdout or $stderr according to exit code.
-
#exit? ⇒ Boolean
Returns true if exit code is not nil.
-
#initialize(*args) ⇒ Error
constructor
Creates an Exit instance.
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
#command ⇒ Object
Quickl command under execution
20 21 22 |
# File 'lib/quickl/errors.rb', line 20 def command @command end |
#exit_code ⇒ Object (readonly)
Exit code
23 24 25 |
# File 'lib/quickl/errors.rb', line 23 def exit_code @exit_code end |
Instance Method Details
#do_kernel_exit ⇒ Object
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. Kernel.exit(exit_code) if exit? end |
#error_io ⇒ Object
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
32 33 34 |
# File 'lib/quickl/errors.rb', line 32 def exit? !exit_code.nil? end |