Class: Rubikon::Config::Factory
Overview
The configuration factory is used to load one or more configuration files from different search paths and using different file formats, e.g. YAML.
Constant Summary collapse
- PROVIDERS =
Providers available for use
[ :auto, :ini, :yaml ]
Instance Attribute Summary collapse
-
#config ⇒ Hash
readonly
The configuration data loaded from the configuration files found inside the search paths.
-
#files ⇒ Array<String>
readonly
The paths of the configuration files found and loaded.
Instance Method Summary collapse
-
#initialize(name, search_paths, provider = :yaml) ⇒ Factory
constructor
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.
-
#save_config(config, file) ⇒ Object
Save the given configuration into the specified file.
Constructor Details
#initialize(name, search_paths, provider = :yaml) ⇒ Factory
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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 |
Instance Attribute Details
#config ⇒ Hash (readonly)
Returns The configuration data loaded from the configuration files found inside the search paths.
31 32 33 |
# File 'lib/rubikon/config/factory.rb', line 31 def config @config end |
#files ⇒ Array<String> (readonly)
Returns The paths of the configuration files found and loaded.
35 36 37 |
# File 'lib/rubikon/config/factory.rb', line 35 def files @files end |
Instance Method Details
#save_config(config, file) ⇒ Object
Save the given configuration into the specified file
66 67 68 69 70 71 72 |
# 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 |