Class: RgGen::Options::OptionSwitch

Inherits:
Object
  • Object
show all
Defined in:
lib/rggen/options.rb

Instance Method Summary collapse

Constructor Details

#initialize(kind) ⇒ OptionSwitch

Returns a new instance of OptionSwitch.



6
7
8
# File 'lib/rggen/options.rb', line 6

def initialize(kind)
  @kind = kind
end

Instance Method Details

#body(&block) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/rggen/options.rb', line 41

def body(&block)
  if block_given?
    @body = block
  else
    @body || proc { |v, o, k| o[k] = v }
  end
end

#default(value = nil, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/rggen/options.rb', line 20

def default(value = nil, &block)
  if block_given?
    @default  = block
  elsif value
    @default  = proc { value }
  else
    @default && @default.call
  end
end

#description(value = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/rggen/options.rb', line 30

def description(value = nil)
  if value
    @description  = value
  elsif @description || @default
    ''.tap do |d|
      d << @description if @description
      d << "(default: #{default})" if default
    end
  end
end

#on(parser, options) ⇒ Object



10
11
12
13
14
# File 'lib/rggen/options.rb', line 10

def on(parser, options)
  parser.on(*args) do |value|
    parser.instance_exec(value, options, @kind, &body)
  end
end