Class: OneviewSDK::Config

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

Overview

Configuration helper class to allow .yaml and .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



22
23
24
25
26
27
28
29
# File 'lib/oneview-sdk/config_loader.rb', line 22

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)
  JSON.parse(data.to_json) # Convert to and from JSON to ensure compatibility
end