Class: CLIConfig::Option
- Inherits:
-
Virtus::Attribute
- Object
- Virtus::Attribute
- CLIConfig::Option
- Defined in:
- lib/cli_config/option.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.[](type) ⇒ Object
5 6 7 8 9 |
# File 'lib/cli_config/option.rb', line 5 def self.[](type) Class.new(self).tap do |klass| klass.define_singleton_method(:type) { type } end end |
Instance Method Details
#coerce(value) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/cli_config/option.rb', line 11 def coerce(value) Virtus::Attribute.build( self.class.type, strict: [:strict] ).coerce(value) end |
#from_option_parser(parser, &block) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/cli_config/option.rb', line 18 def from_option_parser(parser, &block) if boolean? parser.on("-#{key}", "--[no-]#{long_key}", description, &block) else parser.on("-#{key}", "--#{long_key} #{value_name}", description, &block) end end |