Class: RabbitJobs::Configuration
- Inherits:
-
Object
- Object
- RabbitJobs::Configuration
- Defined in:
- lib/rabbit_jobs/configuration.rb
Overview
Configuration DSL.
Constant Summary collapse
- DEFAULT_EXCHANGE_PARAMS =
{ auto_delete: false, durable: true }
- DEFAULT_QUEUE_PARAMS =
{ auto_delete: false, exclusive: false, durable: true, manual_ack: true }
- DEFAULT_MESSAGE_PARAMS =
{ persistent: true, mandatory: true, immediate: false }
Instance Method Summary collapse
- #[](name) ⇒ Object
- #convert_yaml_config(yaml) ⇒ Object
- #disable_error_log ⇒ Object
- #error_log ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #load_file(filename) ⇒ Object
- #load_yaml(text) ⇒ Object
- #queue(name, params = {}) ⇒ Object
- #queue?(routing_key) ⇒ Boolean
- #routing_keys ⇒ Object
- #server(value = nil) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
26 27 28 29 30 31 32 33 34 |
# File 'lib/rabbit_jobs/configuration.rb', line 26 def initialize @data = { error_log: true, server: 'amqp://localhost', queues: { jobs: DEFAULT_QUEUE_PARAMS } } end |
Instance Method Details
#[](name) ⇒ Object
36 37 38 |
# File 'lib/rabbit_jobs/configuration.rb', line 36 def [](name) @data[name] end |
#convert_yaml_config(yaml) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rabbit_jobs/configuration.rb', line 82 def convert_yaml_config(yaml) yaml = parse_environment(yaml) @data = { queues: {} } %w(server).each do |m| send(m, yaml[m]) end yaml['queues'].each do |name, params| queue name, params.symbolize_keys || {} end end |
#disable_error_log ⇒ Object
44 45 46 |
# File 'lib/rabbit_jobs/configuration.rb', line 44 def disable_error_log @data[:error_log] = false end |
#error_log ⇒ Object
40 41 42 |
# File 'lib/rabbit_jobs/configuration.rb', line 40 def error_log @data[:error_log] end |
#load_file(filename) ⇒ Object
74 75 76 |
# File 'lib/rabbit_jobs/configuration.rb', line 74 def load_file(filename) load_yaml(File.read(filename)) end |
#load_yaml(text) ⇒ Object
78 79 80 |
# File 'lib/rabbit_jobs/configuration.rb', line 78 def load_yaml(text) convert_yaml_config(YAML.load(text)) end |
#queue(name, params = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rabbit_jobs/configuration.rb', line 53 def queue(name, params = {}) fail ArgumentError, "name is #{name.inspect}" unless name && name.is_a?(String) && name != '' fail ArgumentError, "params is #{params.inspect}" unless params && params.is_a?(Hash) name = name.downcase.to_sym if @data[:queues][name] @data[:queues][name].merge!(params) else @data[:queues][name] = DEFAULT_QUEUE_PARAMS.merge(params) end end |
#queue?(routing_key) ⇒ Boolean
70 71 72 |
# File 'lib/rabbit_jobs/configuration.rb', line 70 def queue?(routing_key) routing_keys.include?(routing_key.to_sym) end |
#routing_keys ⇒ Object
66 67 68 |
# File 'lib/rabbit_jobs/configuration.rb', line 66 def routing_keys @data[:queues].keys end |
#server(value = nil) ⇒ Object
48 49 50 51 |
# File 'lib/rabbit_jobs/configuration.rb', line 48 def server(value = nil) @data[:server] = value.to_s.strip if value && value.length > 0 @data[:server] end |
#to_hash ⇒ Object
22 23 24 |
# File 'lib/rabbit_jobs/configuration.rb', line 22 def to_hash @data.dup end |