Class: Choosy::Option
Constant Summary
Constants inherited from Argument
Argument::MANY_ARITY, Argument::ONE_ARITY, Argument::ZERO_ARITY
Instance Attribute Summary collapse
-
#default_value ⇒ Object
Returns the value of attribute default_value.
-
#dependent_options ⇒ Object
Returns the value of attribute dependent_options.
-
#description ⇒ Object
Returns the value of attribute description.
-
#long_flag ⇒ Object
Returns the value of attribute long_flag.
-
#name ⇒ Object
Returns the value of attribute name.
-
#negation ⇒ Object
Returns the value of attribute negation.
-
#short_flag ⇒ Object
Returns the value of attribute short_flag.
Attributes inherited from Argument
#allowable_values, #arity, #cast_to, #metaname, #validation_step
Instance Method Summary collapse
- #finalize! ⇒ Object
-
#initialize(name) ⇒ Option
constructor
A new instance of Option.
- #negated ⇒ Object
- #negated? ⇒ Boolean
Methods inherited from Argument
#boolean!, #boolean?, #multiple!, #multiple?, #required=, #required?, #restricted?, #single!, #single?
Constructor Details
#initialize(name) ⇒ Option
Returns a new instance of Option.
9 10 11 12 |
# File 'lib/choosy/option.rb', line 9 def initialize(name) super() @name = name end |
Instance Attribute Details
#default_value ⇒ Object
Returns the value of attribute default_value.
5 6 7 |
# File 'lib/choosy/option.rb', line 5 def default_value @default_value end |
#dependent_options ⇒ Object
Returns the value of attribute dependent_options.
6 7 8 |
# File 'lib/choosy/option.rb', line 6 def @dependent_options end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/choosy/option.rb', line 3 def description @description end |
#long_flag ⇒ Object
Returns the value of attribute long_flag.
4 5 6 |
# File 'lib/choosy/option.rb', line 4 def long_flag @long_flag end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/choosy/option.rb', line 3 def name @name end |
#negation ⇒ Object
Returns the value of attribute negation.
7 8 9 |
# File 'lib/choosy/option.rb', line 7 def negation @negation end |
#short_flag ⇒ Object
Returns the value of attribute short_flag.
4 5 6 |
# File 'lib/choosy/option.rb', line 4 def short_flag @short_flag end |
Instance Method Details
#finalize! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/choosy/option.rb', line 22 def finalize! @arity ||= ZERO_ARITY @cast_to ||= boolean? ? :boolean : :string if boolean? if restricted? raise Choosy::ConfigurationError.new("Options cannot be both boolean and restricted to certain arguments: #{@name}") elsif negated? && @long_flag.nil? raise Choosy::ConfigurationError.new("The long flag is required for negation: #{@name}") end @default_value ||= false else if negated? raise Choosy::ConfigurationError.new("Unable to negate a non-boolean option: #{@name}") end end end |
#negated ⇒ Object
18 19 20 |
# File 'lib/choosy/option.rb', line 18 def negated @negated ||= long_flag.gsub(/^--/, "--#{negation}-") end |
#negated? ⇒ Boolean
14 15 16 |
# File 'lib/choosy/option.rb', line 14 def negated? !negation.nil? end |