class Rubikon::Config::AutoProvider
A configuration provider loading various configuration file formats using another provider depending on the extension of the configuration file.
@author Sebastian Staudt @since 0.5.0
Public Class Methods
Load a configuration file with the corresponding provider detected from the file extension
@param [String] file The path of the config file to load @return [Hash] The configuration values loaded from the file @see IniProvider
@see YamlProvider
# File lib/rubikon/config/auto_provider.rb, line 24 def self.load_config(file) provider_for(file).load_config(file) end
Saves a configuration Hash with the corresponding provider detected from the file extension
@param [Hash] config The configuration to write @param [String] file The path of the file to write @see IniProvider
@see YamlProvider
@since 0.6.0
# File lib/rubikon/config/auto_provider.rb, line 36 def self.save_config(config, file) provider_for(file).save_config(config, file) end
Private Instance Methods
Returns the correct provider for the given file
The file format is guessed from the file extension.
@return Object
A provider for the given file format @since 0.6.0
# File lib/rubikon/config/auto_provider.rb, line 48 def provider_for(file) ext = File.extname(file) case ext when '.ini' IniProvider when '.yaml', '.yml' YamlProvider else raise UnsupportedConfigFormatError.new(ext) end end