lib/rabbit_feed/configuration.rb in rabbit_feed-2.4.4 vs lib/rabbit_feed/configuration.rb in rabbit_feed-3.0.0
- old
+ new
@@ -5,12 +5,12 @@
attr_reader :host, :hosts, :port, :user, :password, :application, :environment, :exchange, :heartbeat,
:connect_timeout, :network_recovery_interval, :auto_delete_queue, :auto_delete_exchange,
:consumer_exit_after_fail
validates_presence_of :application, :environment, :exchange
- def initialize options
- RabbitFeed.log.info {{ event: :initialize_configuration, options: options.merge({password: :redacted}) }}
+ def initialize(options)
+ RabbitFeed.log.info { { event: :initialize_configuration, options: options.merge(password: :redacted) } }
@host = options[:host]
@hosts = options[:hosts]
@port = options[:port]
@user = options[:user]
@@ -26,14 +26,14 @@
@route_prefix_extension = options[:route_prefix_extension]
@consumer_exit_after_fail = options[:consumer_exit_after_fail] || false
validate!
end
- def self.load file_path, environment, application
- RabbitFeed.log.info {{ event: :load_configuration_file, file_path: file_path, environment: environment, application: application }}
+ def self.load(file_path, environment, application)
+ RabbitFeed.log.info { { event: :load_configuration_file, file_path: file_path, environment: environment, application: application } }
- raise ConfigurationError.new "The RabbitFeed configuration file path specified does not exist: #{file_path}" unless (File.exist? file_path)
+ raise ConfigurationError, "The RabbitFeed configuration file path specified does not exist: #{file_path}" unless File.exist? file_path
options = read_configuration_file file_path, environment
options[:environment] = environment
options[:application] = application if !!application
new options
@@ -46,11 +46,11 @@
def queue
"#{environment}#{route_prefix_extension}.#{application}"
end
def connection_options
- Hash.new.tap do |options|
+ {}.tap do |options|
options[:heartbeat] = heartbeat if heartbeat
options[:connect_timeout] = connect_timeout if connect_timeout
options[:host] = host if host
options[:hosts] = hosts if hosts
options[:user] = user if user
@@ -63,15 +63,16 @@
end
end
private
- def self.read_configuration_file file_path, environment
+ def self.read_configuration_file(file_path, environment)
raw_configuration = YAML.load(ERB.new(File.read(file_path)).result)
- HashWithIndifferentAccess.new (raw_configuration[environment] || {})
+ HashWithIndifferentAccess.new(raw_configuration[environment] || {})
end
+ private_class_method :read_configuration_file
def validate!
- raise ConfigurationError.new errors.messages if invalid?
+ raise ConfigurationError, errors.messages if invalid?
end
end
end