Class: Rubikon::Config::AutoProvider

Inherits:
Object
  • Object
show all
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.

Author:

  • Sebastian Staudt

Since:

  • 0.5.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_config(file) ⇒ Hash

Load a configuration file with the corresponding provider detected from the file extension

Parameters:

  • file (String)

    The path of the config file to load

Returns:

  • (Hash)

    The configuration values loaded from the file

See Also:

Since:

  • 0.5.0



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

Parameters:

  • config (Hash)

    The configuration to write

  • file (String)

    The path of the file to write

See Also:

Since:

  • 0.6.0



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.

Returns:

  • Object A provider for the given file format

Since:

  • 0.6.0



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