Class: QAT::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Environment, Parser, Logger, Utils::Network
Defined in:
lib/qat/configuration.rb,
lib/qat/configuration/parser.rb,
lib/qat/configuration/environment.rb

Overview

This class represents QAT‘s Configuration manager

This class should be used to manage configurations from multiple environments in test projects. Given a defined environment, all configurations for that environment will be loaded into a cache from the corresponding folder (with the same name) under the config directory.

A common folder is also supported which contains configurations shared between multiple environments. A configuration file can exist in both the environment folder and the common folder with the content of both being merged at load time and the configuration from the environment taking precedence over the shared (common) configuration.

Also supported is the cross-referencing of configurations between files. Given a file ‘foo.yml’ with a configuration ‘foo: bar’ and a second file ‘baz.yml’ with configuration ‘baz: foo.foo’, after configurations are loaded to cache, the value of ‘baz’ in cache will be ‘bar’. Cross-referencing between files is made with syntax:

  • <file.yml>

    `
    key: <other_file.yml>.<key>
    `
    

Since:

  • 0.1.0

Defined Under Namespace

Modules: Environment, Parser Classes: InvalidFolderName, NoEnvironmentDefined, NoEnvironmentFolder

Instance Attribute Summary

Attributes included from Environment

#environment

Instance Method Summary collapse

Methods included from Environment

#each_environment, #environments

Methods included from Utils::Network

#is_ip?

Constructor Details

#initialize(directory = Dir.pwd, environment = nil) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

  • directory (String) (defaults to: Dir.pwd)

    path to configuration directory

  • environment (String) (defaults to: nil)

    name of the environment from which configurations will be loaded

Since:

  • 0.1.0



53
54
55
56
57
58
# File 'lib/qat/configuration.rb', line 53

def initialize(directory=Dir.pwd, environment=nil)
  self.directory = directory
  log.info { "Initializing configuration from directory #{self.directory}" }
  self.environment = validate_environment(environment)
  log.info { "Initialized configuration with environment '#{self.environment}'" }
end

Instance Method Details

#[](key) ⇒ Object

Returns a copy from cache to avoid data manipulation on runtime

Parameters:

  • key (String|Symbol)

    cache key

Returns:

  • (Object)

Since:

  • 0.1.0



63
64
65
# File 'lib/qat/configuration.rb', line 63

def [](key)
  @cache[key].deep_dup
end

#directoryObject

Since:

  • 0.1.0



67
68
69
# File 'lib/qat/configuration.rb', line 67

def directory
  super
end