Module: RakeCommander::Options::Error::Handling::ClassMethods
- Defined in:
- lib/rake-commander/options/error/handling.rb
Instance Attribute Summary collapse
-
#options_latest_error ⇒ Object
readonly
Returns the value of attribute options_latest_error.
Instance Method Summary collapse
- #error_on_leftovers(action = :not_used, &handler) ⇒ Object
-
#error_on_options(action = :not_used, error: RakeCommander::Options::Error::Base) {|error, argv, results, leftovers| ... } ⇒ Boolean
Whether it should trigger an error when there are
ARGV
option errors duringparse_options
. -
#error_on_options?(error = RakeCommander::Options::Error::Base) ⇒ Boolean
Whether there is an error
action
defined forerror
.
Instance Attribute Details
#options_latest_error ⇒ Object (readonly)
Returns the value of attribute options_latest_error.
16 17 18 |
# File 'lib/rake-commander/options/error/handling.rb', line 16 def @options_latest_error end |
Instance Method Details
#error_on_leftovers(action = :not_used, &handler) ⇒ Object
59 60 61 |
# File 'lib/rake-commander/options/error/handling.rb', line 59 def error_on_leftovers(action = :not_used, &handler) (action, error: RakeCommander::Options::Error::UnknownArgument, &handler) end |
#error_on_options(action = :not_used, error: RakeCommander::Options::Error::Base) {|error, argv, results, leftovers| ... } ⇒ Boolean
Note:
- It triggers error by default when there are parsing option errors.
- Even if a
handler
block is defined, if action isfalse
it won't trigger error. - When specific errors are NOT specified, they will fallback to the action defined
on the parent class
RakeCommander::Options::Error::Base
. This means that you can define a default behaviour for this.
Whether it should trigger an error when there are ARGV
option errors during parse_options
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rake-commander/options/error/handling.rb', line 41 def (action = :not_used, error: RakeCommander::Options::Error::Base, &handler) RakeCommander::Options::Error::Base.require_argument!(error, :error, accept_children: true) @options_latest_error = nil @error_on_options ||= {} @error_on_options[error] = action if action != :not_used if block_given? (error, &handler) @error_on_options[error] ||= true end return self unless block_given? || action != :not_used # default value @error_on_options[error] = true unless @error_on_options[error] == false @error_on_options[error] end |
#error_on_options?(error = RakeCommander::Options::Error::Base) ⇒ Boolean
Returns whether there is an error action
defined for error
.
64 65 66 67 68 |
# File 'lib/rake-commander/options/error/handling.rb', line 64 def (error = RakeCommander::Options::Error::Base) RakeCommander::Options::Error::Base.require_argument!(error, :error, accept_children: true) _default_action = @error_on_options.key?(error) || .key?(error) end |