Class: RgGen::Core::Options::Option

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

Instance Method Summary collapse

Constructor Details

#initialize(option_name) ⇒ Option

Returns a new instance of Option.



9
10
11
12
# File 'lib/rggen/core/options.rb', line 9

def initialize(option_name)
  @option_name = option_name
  block_given? && yield(self)
end

Instance Method Details

#action(&block) ⇒ Object



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

def action(&block)
  if block_given?
    @action = block
  else
    @action || default_action
  end
end

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



23
24
25
26
27
28
29
30
31
# File 'lib/rggen/core/options.rb', line 23

def default(value = nil, &block)
  if block_given?
    @default = block
  elsif !value.nil?
    @default = -> { value }
  elsif @default
    instance_exec(&@default)
  end
end

#description(value = nil) ⇒ Object



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

def description(value = nil)
  if value
    @description = value
  else
    @description
  end
end

#enable(parser, options) ⇒ Object



14
15
16
17
# File 'lib/rggen/core/options.rb', line 14

def enable(parser, options)
  options[@option_name] ||= default
  parser.on(*args) { |value| handler(value, options, parser) }
end