Class: Ergane::SwitchDefinition
- Inherits:
-
Object
- Object
- Ergane::SwitchDefinition
- Defined in:
- lib/ergane/switch_definition.rb
Instance Attribute Summary collapse
-
#argument ⇒ Object
readonly
Returns the value of attribute argument.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#run_block ⇒ Object
readonly
Returns the value of attribute run_block.
-
#short ⇒ Object
readonly
Returns the value of attribute short.
Instance Method Summary collapse
- #attach(option_parser, command, &block) ⇒ Object
-
#initialize(label, short: nil, argument: nil, kind: nil, description: nil, default: nil, &block) ⇒ SwitchDefinition
constructor
A new instance of SwitchDefinition.
Constructor Details
#initialize(label, short: nil, argument: nil, kind: nil, description: nil, default: nil, &block) ⇒ SwitchDefinition
Returns a new instance of SwitchDefinition.
29 30 31 32 |
# File 'lib/ergane/switch_definition.rb', line 29 def initialize(label, short: nil, argument: nil, kind: nil, description: nil, default: nil, &block) @label, @short, @argument, @kind, @description, @default = label.to_sym, short, argument, kind, description, default @run_block = block if block_given? end |
Instance Attribute Details
#argument ⇒ Object (readonly)
Returns the value of attribute argument.
24 25 26 |
# File 'lib/ergane/switch_definition.rb', line 24 def argument @argument end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
26 27 28 |
# File 'lib/ergane/switch_definition.rb', line 26 def default @default end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
25 26 27 |
# File 'lib/ergane/switch_definition.rb', line 25 def description @description end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
23 24 25 |
# File 'lib/ergane/switch_definition.rb', line 23 def kind @kind end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
21 22 23 |
# File 'lib/ergane/switch_definition.rb', line 21 def label @label end |
#run_block ⇒ Object (readonly)
Returns the value of attribute run_block.
27 28 29 |
# File 'lib/ergane/switch_definition.rb', line 27 def run_block @run_block end |
#short ⇒ Object (readonly)
Returns the value of attribute short.
22 23 24 |
# File 'lib/ergane/switch_definition.rb', line 22 def short @short end |
Instance Method Details
#attach(option_parser, command, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ergane/switch_definition.rb', line 34 def attach(option_parser, command, &block) flag_arg = argument ? "=#{argument}" : "" args = [] args << "-#{short}#{flag_arg}" if short args << "--#{label.to_s.gsub(/_/, '-')}#{flag_arg}" args << kind if kind args << description if description option_parser.on(*args, Proc.new { |value| command.instance_exec(value, &block) if block_given? command.instance_exec(value, &run_block) if run_block }) end |