Method: Roby::Application.attr_config

Defined in:
lib/roby/app.rb

.attr_config(config_key) ⇒ Object

Allows to attribute configuration keys to override configuration parameters stored in config/app.yml

For instance,

attr_config 'log'

creates a log_overrides attribute, which contains a hash. Any value stored in this hash will override those stored in the config file. The final value can be accessed by accessing the generated #config_key method:

E.g.,

in config/app.yml:

log:
    dir: test

in config/init.rb:

Roby.app.log_overrides['dir'] = 'bla'

Then, Roby.app.log will return { ‘dir’ => ‘bla }

This override mechanism is not meant to be used directly by the user, but as a tool for the rest of the framework



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/roby/app.rb', line 189

def self.attr_config(config_key)
    config_key = config_key.to_s

    # Ignore if already done
    return if method_defined?("#{config_key}_overrides")

    attribute("#{config_key}_overrides") { {} }
    define_method(config_key) do
        plain     = self.options[config_key] || {}
        overrides = instance_variable_get "@#{config_key}_overrides"
        if overrides
            plain.recursive_merge(overrides)
        else
            plain
        end
    end
end