class Isimud::TestClient::Queue
Attributes
bindings[R]
client[R]
name[R]
proc[RW]
Public Class Methods
new(client, name, proc = Proc.new { |_|})
click to toggle source
# File lib/isimud/test_client.rb, line 17 def initialize(client, name, proc = Proc.new { |_|}) @client = client @name = name @bindings = Hash.new { |hash, key| hash[key] = Set.new } @proc = proc end
Public Instance Methods
bind(exchange, opts = {})
click to toggle source
# File lib/isimud/test_client.rb, line 24 def bind(exchange, opts = {}) routing_key = opts[:routing_key] log "TestClient: adding routing key #{routing_key} for exchange #{exchange} to queue #{name}" @bindings[exchange] << routing_key end
cancel()
click to toggle source
# File lib/isimud/test_client.rb, line 30 def cancel end
delete(opts = {})
click to toggle source
# File lib/isimud/test_client.rb, line 33 def delete(opts = {}) log "TestClient: delete queue #{name}" @bindings.clear @proc = nil end
deliver(data)
click to toggle source
# File lib/isimud/test_client.rb, line 53 def deliver(data) begin @proc.try(:call, data) rescue => e log "TestClient: error delivering message: #{e.message}\n #{e.backtrace.join("\n ")}", :error client.run_exception_handlers(e) end end
has_matching_key?(exchange, route)
click to toggle source
# File lib/isimud/test_client.rb, line 49 def has_matching_key?(exchange, route) @bindings[exchange].any? { |key| route =~ make_regexp(key) } end
make_regexp(key)
click to toggle source
# File lib/isimud/test_client.rb, line 45 def make_regexp(key) Regexp.new(key.gsub(/\./, "\\.").gsub(/\*/, '[^.]*').gsub(/#/, '.*')) end
unbind(exchange, opts = {})
click to toggle source
# File lib/isimud/test_client.rb, line 39 def unbind(exchange, opts = {}) routing_key = opts[:routing_key] log "TestClient: removing routing key #{routing_key} for exchange #{exchange} from queue #{name}" @bindings[exchange].delete(routing_key) end