Skip to content

Commit

Permalink
Default to ENV['RABBITMQ_URL'] when no connection argument is given
Browse files Browse the repository at this point in the history
- Bunny.new and Bunny.run now defaults to ENV['RABBITMQ_URL'] for connection
  argument.
- Session.new now only uses ENV['RABBITMQ_URL'] for connection argument
  when no other argument is given.
  • Loading branch information
jipe committed May 13, 2016
1 parent 396c7e9 commit e5d8cb3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/bunny.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def self.protocol_version
# @see http://rubybunny.info/articles/getting_started.html
# @see http://rubybunny.info/articles/connecting.html
# @api public
def self.new(connection_string_or_opts = {}, opts = {}, &block)
def self.new(connection_string_or_opts = ENV['RABBITMQ_URL'], opts = {}, &block)
if connection_string_or_opts.respond_to?(:keys) && opts.empty?
opts = connection_string_or_opts
end
Expand All @@ -70,7 +70,7 @@ def self.new(connection_string_or_opts = {}, opts = {}, &block)
end


def self.run(connection_string_or_opts = {}, opts = {}, &block)
def self.run(connection_string_or_opts = ENV['RABBITMQ_URL'], opts = {}, &block)
raise ArgumentError, 'Bunny#run requires a block' unless block

client = Session.new(connection_string_or_opts, opts)
Expand Down
6 changes: 3 additions & 3 deletions lib/bunny/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ class Session
# @see http://rubybunny.info/articles/connecting.html Connecting to RabbitMQ guide
# @see http://rubybunny.info/articles/tls.html TLS/SSL guide
# @api public
def initialize(connection_string_or_opts = Hash.new, optz = Hash.new)
opts = case (ENV["RABBITMQ_URL"] || connection_string_or_opts)
def initialize(connection_string_or_opts = ENV['RABBITMQ_URL'], optz = Hash.new)
opts = case (connection_string_or_opts)
when nil then
Hash.new
when String then
self.class.parse_uri(ENV["RABBITMQ_URL"] || connection_string_or_opts)
self.class.parse_uri(connection_string_or_opts)
when Hash then
connection_string_or_opts
end.merge(optz)
Expand Down

0 comments on commit e5d8cb3

Please sign in to comment.