Class: RgGen::Generator::Option
- Inherits:
-
Object
- Object
- RgGen::Generator::Option
- Defined in:
- lib/rggen/generator.rb
Instance Attribute Summary collapse
- #body ⇒ Object
-
#class ⇒ Object
Returns the value of attribute class.
-
#default ⇒ Object
writeonly
Sets the attribute default.
- #description ⇒ Object
-
#long ⇒ Object
Returns the value of attribute long.
-
#short ⇒ Object
Returns the value of attribute short.
Instance Method Summary collapse
- #args ⇒ Object
- #default_body ⇒ Object
-
#initialize(kind) ⇒ Option
constructor
A new instance of Option.
- #on(parser, options) ⇒ Object
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
#body ⇒ Object
41 42 43 |
# File 'lib/rggen/generator.rb', line 41 def body @body || default_body end |
#class ⇒ Object
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
18 19 20 |
# File 'lib/rggen/generator.rb', line 18 def default=(value) @default = value end |
#description ⇒ Object
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 |
#long ⇒ Object
Returns the value of attribute long.
16 17 18 |
# File 'lib/rggen/generator.rb', line 16 def long @long end |
#short ⇒ Object
Returns the value of attribute short.
15 16 17 |
# File 'lib/rggen/generator.rb', line 15 def short @short end |
Instance Method Details
#args ⇒ Object
29 30 31 |
# File 'lib/rggen/generator.rb', line 29 def args [@short, @long, @class, description].compact end |
#default_body ⇒ Object
45 46 47 48 49 |
# File 'lib/rggen/generator.rb', line 45 def default_body proc do |value, , kind| [kind] = value end end |
#on(parser, options) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/rggen/generator.rb', line 22 def on(parser, ) [@kind] = @default if @default parser.on(*args) do |value| parser.instance_exec(value, , @kind, &body) end end |