Module: BatchKit::Configurable::ClassMethods

Defined in:
lib/batch-kit/configurable.rb

Overview

Defines the methods that are to be added as class methods to the class that includes the Configurable module.

Instance Method Summary collapse

Instance Method Details

#configObject

Returns the BatchKit::Config object produced when loading the configuration files (or creates a new instance if no files were loaded).



42
43
44
# File 'lib/batch-kit/configurable.rb', line 42

def config
    @config ||= Config.new
end

#configure(*cfg_files) ⇒ Object

Configure the class by loading the configuration files specifed. If the last argument passed to this method is a Hash, it is treated an options hash, which is passed into BatchKit::Config.

Parameters:

  • cfg_files (Array<String>)

    Path(s) to the configuration file(s) to be loaded into a single BatchKit::Config object.

Options Hash (*cfg_files):

  • :decryption_key (String)

    The master key for decrypting any encrypted values in the configuration files.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/batch-kit/configurable.rb', line 22

def configure(*cfg_files)
    options = cfg_files.last.is_a?(Hash) ? cfg_files.pop.clone : {}
    if defined?(BatchKit::Events)
        Events.publish(self, 'config.pre-load', config, cfg_files)
    end
    config.decryption_key = options.delete(:decryption_key) if options[:decryption_key]
    config.merge!(options)
    cfg_files.each do |cfg_file|
        config.load(cfg_file, options)
    end
    if defined?(BatchKit::Events)
        Events.publish(self, 'config.post-load', config)
    end
    config
end