Class: Rubikon::Config::YamlProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/rubikon/config/yaml_provider.rb

Overview

A configuration provider loading configuration data from YAML files

Author:

  • Sebastian Staudt

Since:

  • 0.5.0

Class Method Summary collapse

Class Method Details

.load_config(file) ⇒ Hash

Loads a configuration Hash from a YAML formatted file

Parameters:

  • file (String) —

    The path of the file to load

Returns:

  • (Hash) —

    The configuration data loaded from the file

Since:

  • 0.5.0



22
23
24
# File 'lib/rubikon/config/yaml_provider.rb', line 22

def self.load_config(file)
  YAML.load_file file
end

.save_config(config, file) ⇒ Object

Saves a configuration Hash into a YAML formatted file

Parameters:

  • config (Hash) —

    The configuration to write

  • file (String) —

    The path of the file to write

Since:

  • 0.6.0



31
32
33
34
35
36
37
38
39
# File 'lib/rubikon/config/yaml_provider.rb', line 31

def self.save_config(config, file)
  unless config.is_a? Hash
    raise ArgumentError.new('Configuration has to be a Hash')
  end

  file = File.new file, 'w'
  YAML.dump config, file
  file.close
end