Class: Rubikon::Config::AutoProvider
- Defined in:
- lib/rubikon/config/auto_provider.rb
Overview
A configuration provider loading various configuration file formats using another provider depending on the extension of the configuration file.
Class Method Summary collapse
-
.load_config(file) ⇒ Hash
Load a configuration file with the corresponding provider detected from the file extension.
-
.save_config(config, file) ⇒ Object
Saves a configuration Hash with the corresponding provider detected from the file extension.
Instance Method Summary collapse
-
#provider_for(file) ⇒ Object
private
Returns the correct provider for the given file.
Class Method Details
.load_config(file) ⇒ Hash
Load a configuration file with the corresponding provider detected from the file extension
24 25 26 |
# File 'lib/rubikon/config/auto_provider.rb', line 24 def self.load_config(file) provider_for(file).load_config(file) end |
.save_config(config, file) ⇒ Object
Saves a configuration Hash with the corresponding provider detected from the file extension
36 37 38 |
# File 'lib/rubikon/config/auto_provider.rb', line 36 def self.save_config(config, file) provider_for(file).save_config(config, file) end |
Instance Method Details
#provider_for(file) ⇒ Object (private)
Returns the correct provider for the given file
The file format is guessed from the file extension.
48 49 50 51 52 53 54 55 56 57 58 |
# 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 |