Class: Djinn::Base::Dsl::ConfigItem
- Inherits:
-
Object
- Object
- Djinn::Base::Dsl::ConfigItem
- Defined in:
- lib/djinn/base/dsl.rb
Overview
A helper class to hold individual configuration items
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #default(d) ⇒ Object
- #default_value ⇒ Object
-
#description(d) ⇒ Object
Description of the switch.
- #has_default? ⇒ Boolean
-
#initialize(t, key, &block) ⇒ ConfigItem
constructor
A new instance of ConfigItem.
-
#long_switch(s) ⇒ Object
Long configuration switch.
-
#parse!(opts, config) ⇒ Object
Parse the individual configuration option.
-
#required(r) ⇒ Object
Sets whether the switch is required.
-
#required? ⇒ Boolean
Checks whether the switch is required.
-
#short_switch(s) ⇒ Object
Short configuration switch.
Constructor Details
#initialize(t, key, &block) ⇒ ConfigItem
Returns a new instance of ConfigItem.
100 101 102 103 |
# File 'lib/djinn/base/dsl.rb', line 100 def initialize t, key, &block @type, @key = t, key instance_eval(&block) if block_given? end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
98 99 100 |
# File 'lib/djinn/base/dsl.rb', line 98 def key @key end |
Instance Method Details
#default(d) ⇒ Object
132 133 134 |
# File 'lib/djinn/base/dsl.rb', line 132 def default d @default = d end |
#default_value ⇒ Object
136 |
# File 'lib/djinn/base/dsl.rb', line 136 def default_value; @default; end |
#description(d) ⇒ Object
Description of the switch
118 119 120 |
# File 'lib/djinn/base/dsl.rb', line 118 def description d @description = d end |
#has_default? ⇒ Boolean
138 139 140 |
# File 'lib/djinn/base/dsl.rb', line 138 def has_default? !@default.nil? end |
#long_switch(s) ⇒ Object
Long configuration switch
112 113 114 115 |
# File 'lib/djinn/base/dsl.rb', line 112 def long_switch s @long_switch = s @long_switch = "--#{@long_switch}" unless @long_switch =~ /^--/ end |
#parse!(opts, config) ⇒ Object
Parse the individual configuration option
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/djinn/base/dsl.rb', line 143 def parse! opts, config @long_switch = "#{@long_switch} #{@key.to_s.upcase}" if @type == :posix and \ defined?(@key) && @key switches = [] switches << (defined?(@short_switch) && @short_switch) ? @short_switch : nil switches << (defined?(@long_switch) && @long_switch) ? @long_switch : nil @description = "#{@description} (Default: #{@default})" if @default opts.on(switches[0], switches[1], @description) do |o| config[@key] = o end end |
#required(r) ⇒ Object
Sets whether the switch is required
123 124 125 |
# File 'lib/djinn/base/dsl.rb', line 123 def required r @required = r end |
#required? ⇒ Boolean
Checks whether the switch is required
128 129 130 |
# File 'lib/djinn/base/dsl.rb', line 128 def required? @required end |
#short_switch(s) ⇒ Object
Short configuration switch
106 107 108 109 |
# File 'lib/djinn/base/dsl.rb', line 106 def short_switch s @short_switch = s @short_switch = "-#{@short_switch}" unless @short_switch =~ /^-/ end |