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
# File 'lib/bunny_exchanges/configuration.rb', line 27

def initialize
  @exchanges_path = DEFAULT_EXCHANGES_PATH
  @rabbitmq_path  = DEFAULT_RABBITMQ_PATH
end

Instance Attribute Details

#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

#rabbitmq_path=(value) ⇒ Object

Sets the path of the rabbitmq configuration file.

Parameters:

  • a (String)

    path.



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

def rabbitmq_path=(value)
  @rabbitmq_path = value
end

Instance Method Details

#exchangesHash

Loads the configuration YAML file contents.

Returns:

  • (Hash)

    the exchanges configuration.



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

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

#rabbitmqHash

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

Returns:

  • (Hash)

    the rabbitmq configuration.



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

def rabbitmq
  @rabbitmq ||= if env
                  rabbitmq_contents.fetch(env)
                else
                  rabbitmq_contents
                end
end