class Rubikon::Config::Factory

The configuration factory is used to load one or more configuration files from different search paths and using different file formats, e.g. YAML.

@author Sebastian Staudt

Constants

PROVIDERS

Providers available for use

Attributes

config[R]

@return [Hash] The configuration data loaded from the configuration

files found inside the search paths
files[R]

@return [Array<String>] The paths of the configuration files found and

loaded

Public Class Methods

new(name, search_paths, provider = :yaml) click to toggle source

Creates a new factory instance with a given file name to be searched in the given paths and using the specified provider to load the configuration data from the files.

@param [String] name The name of the configuration file @param [Array<String>] search_paths An array of paths to be searched

for configuration files

@param [PROVIDERS] provider The provider to use for loading

configuration data from the files found
# File lib/rubikon/config/factory.rb, line 46
def initialize(name, search_paths, provider = :yaml)
  provider = :auto unless PROVIDERS.include?(provider)
  @provider = Config.const_get("#{provider.to_s.capitalize}Provider")

  @files  = []
  @config = {}
  search_paths.each do |path|
    config_file = File.join path, name
    if File.exists? config_file
      @config.merge! @provider.load_config(config_file)
      @files << config_file
    end
  end
end

Public Instance Methods

save_config(config, file) click to toggle source

Save the given configuration into the specified file

@param [Hash] The configuration to save @param [String] The file path where the configuration should be saved @since 0.6.0

# File lib/rubikon/config/factory.rb, line 66
def save_config(config, file)
  unless config.is_a? Hash
    raise ArgumentError.new('Configuration has to be a Hash')
  end

  @provider.save_config config, file
end