summaryrefslogtreecommitdiff
path: root/lib/killjoy/amqp_configuration.rb
blob: 62262f8562bf0b043c96656c465e9fe83ebdb092 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module Killjoy
  class AMQPConfiguration
    attr_reader :environment

    def initialize(environment: ENV.fetch("ENV", "development"))
      @environment = environment
    end

    def amqp_uri
      configuration['amqp_uri']
    end

    def heartbeat
      configuration['heartbeat'].to_i
    end

    def prefetch
      configuration['prefetch'].to_i
    end

    def exchange
      configuration['exchange']
    end

    def exchange_type
      configuration['exchange_type']
    end

    def shards
      configuration['shards'].to_i
    end

    def to_hash
      configuration
    end

    private

    def configuration(file = "config/amqp.yml")
      @configuration ||= YAML.load(expand_template(file))[environment]
    end

    def expand_template(file)
      ERB.new(File.read(file)).result(binding)
    end
  end
end