Class: Aker::CentralParameters

Inherits:
Hash
  • Object
show all
Defined in:
lib/aker/central_parameters.rb

Overview

Provides consistent access to server-based defaults for configuration parameters. These defaults are stored in a YAML file on the server and updated separately from application deployments. E.g., you might have the following in /etc/nubic/aker-prod.yml:

ldap:
  server: ldap.example.org
  user: cn=foo
  password: 13635;nefvqerg35245gk
policy:
  session_timeout_seconds: 1500

The top level keys in this file correspond to parameter groups in a Configuration. If this file were loaded like so,

Aker.configure {
  central '/etc/nubic/aker-prod.yml'
}

it would be equivalent to the following:

Aker.configure {
  ldap_parameters :server => 'ldap.example.org',
                  :user => 'cn=foo',
                  :password => '13635;nefvqerg35245gk'
  policy_parameters :session_timeout_seconds => 1500
}

The central approach has several benefits:

  • It is simultaneously updateable for all applications on a server.
  • It separates system administration tasks from application developer concerns.
  • It provides an easy alternative to checking sensitive information (in this example, the LDAP password) into the VCS.
  • No flexibility is lost — individual applications may still override parameter values if necessary.

See Also:

Instance Method Summary (collapse)

Constructor Details

- (CentralParameters) initialize(values = {})

Creates a new instance with the given overrides.

Parameters:

  • values (String, Hash) (defaults to: {})

    if a hash, it is used as a set of overrides directly. Otherwise it is interpreted as the filename for the system central parameters YAML file.



56
57
58
59
60
61
62
63
64
65
# File 'lib/aker/central_parameters.rb', line 56

def initialize(values = {})
  super

  unless values.is_a? Hash
    values = YAML::load( File.open(values) )
  end

  values = nested_symbolize_keys!(deep_clone(values))
  update(values)
end

Instance Method Details

- (Object) [](key)

Returns the value or (more likely) hash of values corresponding to the given top-level configuration section.

Note that, no matter the structure of the values hash provided on construction, all keys in any hashes returned by this method will be symbols.

Parameters:

  • key (Symbol)

    the configuration section to access



76
77
78
# File 'lib/aker/central_parameters.rb', line 76

def [](key)
  super
end