Module: Filigree::Configuration::ClassMethods
- Defined in:
- lib/filigree/configuration.rb
Overview
Class Methods #
Instance Attribute Summary collapse
-
#options_long ⇒ Hash<String, Option>
readonly
Hash of options with long names used as keys.
-
#options_short ⇒ Hash<String, Option>
readonly
Hash of options with short name used as keys.
Class Method Summary collapse
-
.extended(klass) ⇒ Object
Callbacks #.
Instance Method Summary collapse
-
#add_option(opt) ⇒ void
Add an option to the necessary data structures.
-
#auto(name, &block) ⇒ void
Define an automatic configuration variable.
-
#bool_option(long, short = nil) ⇒ void
Define a boolean option.
-
#default(val = nil, &block) ⇒ void
Sets the default value for the next command.
-
#help(str) ⇒ void
Sets the help string for the next command.
-
#install_icvars ⇒ void
Install the instance class variables in the including class.
-
#option(long, short = nil, conversions: nil, &block) ⇒ void
Define a new option.
-
#required(*names) ⇒ void
Mark some options as required.
-
#required_options ⇒ Array<Symbol>
Options that need to be marked as required.
-
#string_option(long, short = nil) ⇒ void
Define an option that takes a single string argument.
-
#usage(str = nil) ⇒ String
Add’s a usage string to the entire configuration object.
Instance Attribute Details
Class Method Details
.extended(klass) ⇒ Object
Callbacks #
328 329 330 |
# File 'lib/filigree/configuration.rb', line 328 def self.extended(klass) klass.install_icvars end |
Instance Method Details
#add_option(opt) ⇒ void
This method returns an undefined value.
Add an option to the necessary data structures.
198 199 200 201 |
# File 'lib/filigree/configuration.rb', line 198 def add_option(opt) [opt.long] = opt [opt.short] = opt unless opt.short.nil? end |
#auto(name, &block) ⇒ void
This method returns an undefined value.
Define an automatic configuration variable.
209 210 211 |
# File 'lib/filigree/configuration.rb', line 209 def auto(name, &block) define_method(name, &block) end |
#bool_option(long, short = nil) ⇒ void
This method returns an undefined value.
Define a boolean option. The variable will be set to true if the flag is seen and be false otherwise.
220 221 222 223 |
# File 'lib/filigree/configuration.rb', line 220 def bool_option(long, short = nil) @next_default = false option(long, short) { true } end |
#default(val = nil, &block) ⇒ void
This method returns an undefined value.
Sets the default value for the next command. If a block is provided it will be used. If not, the val parameter will be.
232 233 234 |
# File 'lib/filigree/configuration.rb', line 232 def default(val = nil, &block) @next_default = block ? block : val end |
#help(str) ⇒ void
This method returns an undefined value.
Sets the help string for the next command.
241 242 243 |
# File 'lib/filigree/configuration.rb', line 241 def help(str) @help_string = str end |
#install_icvars ⇒ void
This method returns an undefined value.
Install the instance class variables in the including class.
248 249 250 251 252 253 254 255 256 |
# File 'lib/filigree/configuration.rb', line 248 def install_icvars @help_string = '' @next_default = nil @next_required = false = Hash.new = Hash.new @required = Array.new @usage = '' end |
#option(long, short = nil, conversions: nil, &block) ⇒ void
This method returns an undefined value.
Define a new option.
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/filigree/configuration.rb', line 266 def option(long, short = nil, conversions: nil, &block) attr_accessor long.to_sym long = long.to_s short = short.to_s if short add_option Option.new(long, short, @help_string, @next_default, conversions.nil? ? block : conversions) @required << long.to_sym if @next_required # Reset state between option declarations. @help_string = '' @next_default = nil @next_required = false end |
#required(*names) ⇒ void
This method returns an undefined value.
Mark some options as required. If no names are provided then the next option to be defined is required; if names are provided they are all marked as required.
291 292 293 294 295 296 297 |
# File 'lib/filigree/configuration.rb', line 291 def required(*names) if names.empty? @next_required = true else @required += names end end |
#required_options ⇒ Array<Symbol>
Returns Options that need to be marked as required.
300 301 302 |
# File 'lib/filigree/configuration.rb', line 300 def @required end |
#string_option(long, short = nil) ⇒ void
This method returns an undefined value.
Define an option that takes a single string argument.
310 311 312 |
# File 'lib/filigree/configuration.rb', line 310 def string_option(long, short = nil) option(long, short) { |str| str } end |
#usage(str = nil) ⇒ String
Add’s a usage string to the entire configuration object. If no string is provided the current usage string is returned.
320 321 322 |
# File 'lib/filigree/configuration.rb', line 320 def usage(str = nil) if str then @usage = str else @usage end end |