class RabbitJobs::Configuration
Configuration
DSL.
Constants
- DEFAULT_EXCHANGE_PARAMS
- DEFAULT_MESSAGE_PARAMS
- DEFAULT_QUEUE_PARAMS
Public Class Methods
new()
click to toggle source
# File lib/rabbit_jobs/configuration.rb, line 26 def initialize @data = { error_log: true, server: 'amqp://localhost', queues: { jobs: DEFAULT_QUEUE_PARAMS } } end
Public Instance Methods
[](name)
click to toggle source
# File lib/rabbit_jobs/configuration.rb, line 36 def [](name) @data[name] end
convert_yaml_config(yaml)
click to toggle source
# 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()
click to toggle source
# File lib/rabbit_jobs/configuration.rb, line 44 def disable_error_log @data[:error_log] = false end
error_log()
click to toggle source
# File lib/rabbit_jobs/configuration.rb, line 40 def error_log @data[:error_log] end
load_file(filename)
click to toggle source
# File lib/rabbit_jobs/configuration.rb, line 74 def load_file(filename) load_yaml(File.read(filename)) end
load_yaml(text)
click to toggle source
# File lib/rabbit_jobs/configuration.rb, line 78 def load_yaml(text) convert_yaml_config(YAML.load(text)) end
queue(name, params = {})
click to toggle source
# 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)
click to toggle source
# File lib/rabbit_jobs/configuration.rb, line 70 def queue?(routing_key) routing_keys.include?(routing_key.to_sym) end
routing_keys()
click to toggle source
# File lib/rabbit_jobs/configuration.rb, line 66 def routing_keys @data[:queues].keys end
server(value = nil)
click to toggle source
# 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()
click to toggle source
# File lib/rabbit_jobs/configuration.rb, line 22 def to_hash @data.dup end
Private Instance Methods
parse_environment(yaml)
click to toggle source
# File lib/rabbit_jobs/configuration.rb, line 96 def parse_environment(yaml) yaml['rabbit_jobs'] || (defined?(Rails) && yaml[Rails.env.to_s]) || yaml end