Exception: RakeCommander::Options::Error::Base
- Inherits:
-
Base::CustomError
- Object
- StandardError
- Base::CustomError
- RakeCommander::Options::Error::Base
- Extended by:
- Name
- Defined in:
- lib/rake-commander/options/error/base.rb
Overview
Base error class that does a rely between OptionParser and RakeCommander errors
Direct Known Subclasses
InvalidArgument, InvalidOption, MissingArgument, MissingOption, UnknownArgument
Constant Summary collapse
- OPTION_REGEX =
/(?:argument|option): (?<option>.+)/i.freeze
Constants included from Name
Name::BOOLEAN_NAME_REGEX, Name::BOOLEAN_TOKEN, Name::DOUBLE_HYPHEN_REGEX, Name::HYPEN_REGEX, Name::HYPHEN_START_REGEX, Name::OPTIONAL_REGEX, Name::SINGLE_HYPHEN_REGEX, Name::UNDERSCORE_REGEX, Name::WORD_DELIMITER
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#option ⇒ Object
readonly
Returns the value of attribute option.
Class Method Summary collapse
-
.option_regex(value = :not_used) ⇒ Object
To (re)define the RegExp used to identify the option of an error message.
-
.option_sym(message) ⇒ Object
Identifies the option
Symbol
(short or name) for a given message. -
.require_argument!(error, arg_name, accept_children: true) ⇒ Object
Helper to check if
error
is this class or any children class.
Instance Method Summary collapse
- #from_desc ⇒ Object
-
#initialize(value = nil, from: nil, option: nil) ⇒ Base
constructor
A new instance of Base.
- #name? ⇒ Boolean
- #option_sym ⇒ Object
-
#options ⇒ Object
Options that are related to the error.
- #short? ⇒ Boolean
Methods included from Name
argument_optional?, argument_required?, boolean_name?, capture_argument_with!, capture_arguments_name!, capture_arguments_short!, double_hyphen?, name_argument, name_argument?, name_hyphen, name_sym, name_word_sym, short_hyphen, short_sym, single_hyphen?, valid_name?, valid_short?
Methods inherited from Base::CustomError
Constructor Details
#initialize(value = nil, from: nil, option: nil) ⇒ Base
Returns a new instance of Base.
37 38 39 40 41 |
# File 'lib/rake-commander/options/error/base.rb', line 37 def initialize(value = nil, from: nil, option: nil) @from = from @option = option super(value) end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
35 36 37 |
# File 'lib/rake-commander/options/error/base.rb', line 35 def from @from end |
#option ⇒ Object (readonly)
Returns the value of attribute option.
35 36 37 |
# File 'lib/rake-commander/options/error/base.rb', line 35 def option @option end |
Class Method Details
.option_regex(value = :not_used) ⇒ Object
To (re)define the RegExp used to identify the option of an error message.
20 21 22 23 24 |
# File 'lib/rake-commander/options/error/base.rb', line 20 def option_regex(value = :not_used) @option_regex ||= OPTION_REGEX return @option_regex if value == :not_used @option_regex = value end |
.option_sym(message) ⇒ Object
Identifies the option Symbol
(short or name) for a given message
27 28 29 30 31 32 |
# File 'lib/rake-commander/options/error/base.rb', line 27 def option_sym() return nil unless match = .match(option_regex) option = match[:option] return name_word_sym(option) if option.length > 1 short_sym(option) end |
.require_argument!(error, arg_name, accept_children: true) ⇒ Object
Helper to check if error
is this class or any children class
12 13 14 15 16 17 |
# File 'lib/rake-commander/options/error/base.rb', line 12 def require_argument!(error, arg_name, accept_children: true) msg = "Expecting #{arg_name} to be #{self}" msg << "or child thereof." if accept_children msg << ". Given: #{error.is_a?(Class)? error : error.class}" raise ArgumentError, msg unless error <= self end |
Instance Method Details
#from_desc ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rake-commander/options/error/base.rb', line 60 def from_desc return '' unless from if from.respond_to?(:name) "(#{from.name}) " elsif from.respond_to?(:to_s) "(#{from}) " else '' end end |
#name? ⇒ Boolean
48 49 50 |
# File 'lib/rake-commander/options/error/base.rb', line 48 def name? option_sym.to_s.length > 1 end |
#option_sym ⇒ Object
56 57 58 |
# File 'lib/rake-commander/options/error/base.rb', line 56 def option_sym @option_sym ||= self.class.option_sym() end |
#options ⇒ Object
Options that are related to the error. There may not be any.
44 45 46 |
# File 'lib/rake-commander/options/error/base.rb', line 44 def [option].compact.flatten end |
#short? ⇒ Boolean
52 53 54 |
# File 'lib/rake-commander/options/error/base.rb', line 52 def short? option_sym.to_s.length == 1 end |