Class: BunnyExchanges::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/bunny_exchanges/configuration.rb

Overview

It stores the exchanges configuration.

Constant Summary collapse

DEFAULT_EXCHANGES_PATH =
"config/exchanges.yml"
DEFAULT_RABBITMQ_PATH =
"config/rabbitmq.yml"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Constructor.



27
28
29
30
31
# File 'lib/bunny_exchanges/configuration.rb', line 27

def initialize
  @exchanges_path = DEFAULT_EXCHANGES_PATH
  @connections    = {default: DEFAULT_RABBITMQ_PATH}
  @configs = {}
end

Instance Attribute Details

#connections=(value) ⇒ Object

Sets the hash path of the rabbitmq configuration file.

Parameters:

  • {:connection_name (Hash)

    > “path_to_config.yml”}.



17
18
19
# File 'lib/bunny_exchanges/configuration.rb', line 17

def connections=(value)
  @connections = value
end

#env=(value) ⇒ Object

Sets the ENV. If it is set, the rabbitmq configuration for that env is taken, otherwise it gets the rabbitmq config file contents directly.

Parameters:

  • the (String)

    env.



24
25
26
# File 'lib/bunny_exchanges/configuration.rb', line 24

def env=(value)
  @env = value
end

#exchanges_path=(value) ⇒ Object

Sets the path of the exchanges configuration file.

Parameters:

  • a (String)

    path.



12
13
14
# File 'lib/bunny_exchanges/configuration.rb', line 12

def exchanges_path=(value)
  @exchanges_path = value
end

Instance Method Details

#connection_config(connection_name) ⇒ Hash

Loads the configuration YAML file contents for the environment if given.

Returns:

  • (Hash)

    the rabbitmq configuration.



43
44
45
46
47
48
49
# File 'lib/bunny_exchanges/configuration.rb', line 43

def connection_config connection_name
  @configs[connection_name] ||= if env
    rabbitmq_contents(connection_name).fetch(env)
  else
    rabbitmq_contents connection_name
  end
end

#exchangesHash

Loads the configuration YAML file contents.

Returns:

  • (Hash)

    the exchanges configuration.



36
37
38
# File 'lib/bunny_exchanges/configuration.rb', line 36

def exchanges
  @exchanges ||= YAML.load_file(exchanges_path)
end