summaryrefslogtreecommitdiff
path: root/lib/killjoy/rmq/amqp_configuration.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/killjoy/rmq/amqp_configuration.rb')
-rw-r--r--lib/killjoy/rmq/amqp_configuration.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/killjoy/rmq/amqp_configuration.rb b/lib/killjoy/rmq/amqp_configuration.rb
new file mode 100644
index 0000000..62262f8
--- /dev/null
+++ b/lib/killjoy/rmq/amqp_configuration.rb
@@ -0,0 +1,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