Class: RgGen::Generator::Option

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind) ⇒ Option

Returns a new instance of Option.



11
12
13
# File 'lib/rggen/generator.rb', line 11

def initialize(kind)
  @kind = kind
end

Instance Attribute Details

#bodyObject



41
42
43
# File 'lib/rggen/generator.rb', line 41

def body
  @body || default_body
end

#classObject

Returns the value of attribute class.



17
18
19
# File 'lib/rggen/generator.rb', line 17

def class
  @class
end

#default=(value) ⇒ Object (writeonly)

Sets the attribute default

Parameters:

  • value

    the value to set the attribute default to.



18
19
20
# File 'lib/rggen/generator.rb', line 18

def default=(value)
  @default = value
end

#descriptionObject



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

def description
  return nil unless @description || @default
  d = ''
  d << @description.to_s
  d << "(default: #{@default})" if @default
  d
end

#longObject

Returns the value of attribute long.



16
17
18
# File 'lib/rggen/generator.rb', line 16

def long
  @long
end

#shortObject

Returns the value of attribute short.



15
16
17
# File 'lib/rggen/generator.rb', line 15

def short
  @short
end

Instance Method Details

#argsObject



29
30
31
# File 'lib/rggen/generator.rb', line 29

def args
  [@short, @long, @class, description].compact
end

#default_bodyObject



45
46
47
48
49
# File 'lib/rggen/generator.rb', line 45

def default_body
  proc do |value, options, kind|
    options[kind] = value
  end
end

#on(parser, options) ⇒ Object



22
23
24
25
26
27
# File 'lib/rggen/generator.rb', line 22

def on(parser, options)
  options[@kind]  = @default if @default
  parser.on(*args) do |value|
    parser.instance_exec(value, options, @kind, &body)
  end
end