Module: Diametric::Config

Extended by:
Config
Included in:
Diametric, Config
Defined in:
lib/diametric/config.rb,
lib/diametric/config/environment.rb

Overview

Program-level configuration services including configuration loading and base connections.

Defined Under Namespace

Modules: Environment

Instance Method Summary collapse

Instance Method Details

#configurationHash

The current configuration Diametric will use in #connect!


12
13
14
# File 'lib/diametric/config.rb', line 12

def configuration
  @configuration ||= {}
end

#configured?Boolean

Determine if Diametric has been configured


19
20
21
# File 'lib/diametric/config.rb', line 19

def configured?
  configuration.present?
end

#connect!(configuration) ⇒ Object

Establish a base connection from the supplied configuration hash.


44
45
46
# File 'lib/diametric/config.rb', line 44

def connect!(configuration)
  ::Diametric::Persistence.establish_base_connection(configuration)
end

#load_and_connect!(path, environment = nil) ⇒ Object

Load settings from a compliant diametric.yml file and make a connection. This can be used for easy setup with frameworks other than Rails.

See Persistence for valid options.

Examples:

Configure Diametric.

Diametric.load_and_connect!("/path/to/diametric.yml")

33
34
35
36
37
38
39
# File 'lib/diametric/config.rb', line 33

def load_and_connect!(path, environment = nil)
  settings = Environment.load_yaml(path, environment)
  @configuration = settings.with_indifferent_access
  connect!(configuration)
  peer_setup if Diametric::Persistence.peer?
  configuration
end