Module: Configurable::ClassMethods
- Includes:
- Lazydoc::Attributes
- Defined in:
- lib/configurable/class_methods.rb,
lib/configurable/class_methods.rb
Overview
ClassMethods extends classes that include Configurable and provides methods for declaring configurations.
Instance Attribute Summary collapse
-
#configurations ⇒ Object
readonly
A hash of (key, Delegate) pairs defining the class configurations.
Instance Method Summary collapse
-
#inherited(child) ⇒ Object
:nodoc:.
-
#initialize_configurations ⇒ Object
applies OrderedHashPatch.
-
#parse(argv = ARGV, options = {}) ⇒ Object
Parses configurations from argv in a non-destructive manner by generating a ConfigParser using the configurations for self.
-
#parse!(argv = ARGV, options = {}) ⇒ Object
Same as parse, but removes parsed args from argv.
Instance Attribute Details
#configurations ⇒ Object (readonly)
A hash of (key, Delegate) pairs defining the class configurations.
16 17 18 |
# File 'lib/configurable/class_methods.rb', line 16 def configurations @configurations end |
Instance Method Details
#inherited(child) ⇒ Object
:nodoc:
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/configurable/class_methods.rb', line 18 def inherited(child) # :nodoc: unless child.instance_variable_defined?(:@source_file) caller[0] =~ Lazydoc::CALLER_REGEXP child.instance_variable_set(:@source_file, File.($1)) end # deep duplicate configurations unless child.instance_variable_defined?(:@configurations) duplicate = child.instance_variable_set(:@configurations, configurations.dup) duplicate.each_pair {|key, config| duplicate[key] = config.dup } duplicate.extend(IndifferentAccess) if configurations.kind_of?(IndifferentAccess) end super end |
#initialize_configurations ⇒ Object
applies OrderedHashPatch
389 390 391 |
# File 'lib/configurable/class_methods.rb', line 389 def initialize_configurations # :nodoc: @configurations ||= {} end |
#parse(argv = ARGV, options = {}) ⇒ Object
Parses configurations from argv in a non-destructive manner by generating a ConfigParser using the configurations for self. Returns an array like
- args, config
-
where the args are the arguments that remain after parsing,
and config is a hash of the parsed configs. The parser will is yielded to the block, if given, to register additonal options.
See ConfigParser#parse for more information.
40 41 42 |
# File 'lib/configurable/class_methods.rb', line 40 def parse(argv=ARGV, ={}) # :yields: parser parse!(argv.dup, ) end |
#parse!(argv = ARGV, options = {}) ⇒ Object
Same as parse, but removes parsed args from argv.
45 46 47 48 49 50 51 |
# File 'lib/configurable/class_methods.rb', line 45 def parse!(argv=ARGV, ={}) parser = ConfigParser.new parser.add(configurations) args = parser.parse!(argv, ) [args, parser.config] end |