Class: OneviewSDK::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/oneview-sdk/config_loader.rb

Overview

Configuration helper class to allow .yaml & .json files to be easily used to specify OneView Configuration

Class Method Summary collapse

Class Method Details

.load(path) ⇒ Hash

Load config from .yaml or .json file

Parameters:

  • path (String)

    The full path to the configuration file

Returns:

  • (Hash)

    hash of the configuration


11
12
13
14
15
16
17
18
# File 'lib/oneview-sdk/config_loader.rb', line 11

def self.load(path)
  path = File.join(Dir.pwd, path) unless Pathname.new(path).absolute?
  expanded_path = File.expand_path(path)
  JSON.parse(IO.read(expanded_path))
rescue
  data = YAML.load_file(expanded_path)
  Hash[data.map { |k, v| [k.to_s, v] }]
end