Class: ConfigManager::CombinedConfiguration

Inherits:
Configuration show all
Defined in:
lib/configmanager/combined_configuration.rb

Overview

A configuration class that can merge multiple configuration trees into a single configuration tree. Each addition, overwrites any properties that already existed.

Instance Method Summary collapse

Methods inherited from Configuration

#add_properties, #add_property, #get_property, #has_property?

Constructor Details

#initialize(options = {}) ⇒ CombinedConfiguration

Creates a new empty combined configuration.

Parameters:

  • options (Hash) (defaults to: {})

    configuration options. Supported keys are: :interpolator - an object that can respond to the ‘interpolate’ method. Default is the DefaultInterpolator. :use_interpolator - global flag to specify if the interpolator should be used for this configuration. Default is true.



19
20
21
22
23
# File 'lib/configmanager/combined_configuration.rb', line 19

def initialize(options = {})
  super

  @configurations = {}
end

Instance Method Details

#add_configuration(name, configuration) ⇒ NilClass

Adds a configuration to be merged into this configuration. All existing properties are overwritten.

Parameters:

  • name (String)

    a unique name for this configuration, it can be retrieved later with this name.

  • configuration (ConfigManager::Configuration)

    the configuration to be merged.

Returns:

  • (NilClass)

Raises:



31
32
33
34
35
36
37
# File 'lib/configmanager/combined_configuration.rb', line 31

def add_configuration(name, configuration)
  raise ConfigManager::KeyError.new("Cannot add - Configuration '#{name}' already exists!") if @configurations.has_key?(name)
  @configurations[name] = configuration
  merge_configuration(configuration)

  nil
end

#get_configuration(name) ⇒ ConfigManager::Configuration

Get the configuration identified by the specified name. Raises an exception if the configuration does not exist. Modifying the returned configuration does not update this combined configuration.

Parameters:

  • name (String)

    the configuration to get.

Returns:



45
46
47
48
# File 'lib/configmanager/combined_configuration.rb', line 45

def get_configuration(name)
  raise ConfigManager::PropertyNotFoundError("Cannot get - Configuration '#{name}' does not exist!") unless @configurations.has_key?(name)
  @configurations[name]
end