lib/bunny_mock/exchange.rb in bunny-mock-1.2.2 vs lib/bunny_mock/exchange.rb in bunny-mock-1.3.0

- old
+ new

@@ -1,11 +1,9 @@ # frozen_string_literal: true module BunnyMock class Exchange - class << self - ## # Create a new {BunnyMock::Exchange} instance # # @param [BunnyMock::Channel] channel Channel this exchange will use # @param [String] name Name of exchange @@ -18,11 +16,10 @@ # @return [BunnyMock::Exchange] A new exchange # @see BunnyMock::Channel#exchange # @api public # def declare(channel, name = '', opts = {}) - # get requested type type = opts.fetch :type, :direct # get needed class type klazz = BunnyMock::Exchanges.const_get type.to_s.capitalize @@ -67,11 +64,10 @@ # @return [Boolean] If exchange has been deleted attr_reader :deleted # @private def initialize(channel, name, type, opts) - # store creation information @channel = channel @name = name @opts = opts @type = type @@ -115,11 +111,10 @@ # @see {BunnyMock::Exchanges::Fanout#deliver} # @see {BunnyMock::Exchanges::Headers#deliver} # @api public # def publish(payload, opts = {}) - # handle message sending, varies by type deliver payload, opts, opts.fetch(:routing_key, '') self end @@ -128,11 +123,10 @@ # Delete this exchange # # @api public # def delete(*) - @channel.deregister_exchange self @deleted = true end @@ -146,16 +140,14 @@ # # @return [BunnyMock::Exchange] self # @api public # def bind(exchange, opts = {}) - if exchange.respond_to?(:add_route) # we can do the binding ourselves exchange.add_route opts.fetch(:routing_key, @name), self - else # we need the channel to look up the exchange @channel.xchg_bind self, opts.fetch(:routing_key, @name), exchange end @@ -173,16 +165,14 @@ # # @return [BunnyMock::Exchange] self # @api public # def unbind(exchange, opts = {}) - if exchange.respond_to?(:remove_route) # we can do the unbinding ourselves exchange.remove_route opts.fetch(:routing_key, @name) - else # we need the channel to look up the exchange @channel.xchg_unbind opts.fetch(:routing_key, @name), exchange end @@ -202,16 +192,14 @@ # # @return [Boolean] true if this exchange is bound to the given exchange, false otherwise # @api public # def bound_to?(exchange, opts = {}) - if exchange.respond_to?(:routes_to?) # we can find out on the exchange object exchange.routes_to? self, opts - else # we need the channel to look up the exchange @channel.xchg_bound_to? self, opts.fetch(:routing_key, @name), exchange end @@ -227,12 +215,10 @@ # # @return [Boolean] true if the given queue or exchange matching options is bound to this exchange, false otherwise # @api public # def routes_to?(exchange_or_queue, opts = {}) - route = exchange_or_queue.respond_to?(:name) ? exchange_or_queue.name : exchange_or_queue - @routes.key? opts.fetch(:routing_key, route) end def has_binding?(exchange_or_queue, opts = {}) # rubocop:disable Style/PredicateName warn '[DEPRECATED] `has_binding?` is deprecated. Please use `routes_to?` instead.'