Class: Aker::CentralParameters
- Inherits:
-
Hash
- Object
- Hash
- Aker::CentralParameters
- 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.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the value or (more likely) hash of values corresponding to the given top-level configuration section.
-
#initialize(values = {}) ⇒ CentralParameters
constructor
Creates a new instance with the given overrides.
Constructor Details
#initialize(values = {}) ⇒ CentralParameters
Creates a new instance with the given overrides.
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
#[](key) ⇒ Object
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.
76 77 78 |
# File 'lib/aker/central_parameters.rb', line 76 def [](key) super end |