Class: Isimud::TestClient::Queue
- Inherits:
-
Object
- Object
- Isimud::TestClient::Queue
- Includes:
- Logging
- Defined in:
- lib/isimud/test_client.rb
Instance Attribute Summary collapse
-
#bindings ⇒ Object
readonly
Returns the value of attribute bindings.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#proc ⇒ Object
Returns the value of attribute proc.
Instance Method Summary collapse
- #bind(exchange, opts = {}) ⇒ Object
- #cancel ⇒ Object
- #delete(opts = {}) ⇒ Object
- #deliver(data) ⇒ Object
- #has_matching_key?(exchange, route) ⇒ Boolean
-
#initialize(client, name, proc = Proc.new { |_|}) ⇒ Queue
constructor
A new instance of Queue.
- #make_regexp(key) ⇒ Object
- #unbind(exchange, opts = {}) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(client, name, proc = Proc.new { |_|}) ⇒ Queue
Returns a new instance of Queue.
17 18 19 20 21 22 |
# 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 |
Instance Attribute Details
#bindings ⇒ Object (readonly)
Returns the value of attribute bindings.
14 15 16 |
# File 'lib/isimud/test_client.rb', line 14 def bindings @bindings end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
14 15 16 |
# File 'lib/isimud/test_client.rb', line 14 def client @client end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/isimud/test_client.rb', line 14 def name @name end |
#proc ⇒ Object
Returns the value of attribute proc.
15 16 17 |
# File 'lib/isimud/test_client.rb', line 15 def proc @proc end |
Instance Method Details
#bind(exchange, opts = {}) ⇒ Object
24 25 26 27 28 |
# 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 ⇒ Object
30 31 |
# File 'lib/isimud/test_client.rb', line 30 def cancel end |
#delete(opts = {}) ⇒ Object
33 34 35 36 37 |
# File 'lib/isimud/test_client.rb', line 33 def delete(opts = {}) log "TestClient: delete queue #{name}" @bindings.clear @proc = nil end |
#deliver(data) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/isimud/test_client.rb', line 53 def deliver(data) begin @proc.try(:call, data) rescue => e log "TestClient: error delivering message: #{e.}\n #{e.backtrace.join("\n ")}", :error client.run_exception_handlers(e) end end |
#has_matching_key?(exchange, route) ⇒ Boolean
49 50 51 |
# 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) ⇒ Object
45 46 47 |
# File 'lib/isimud/test_client.rb', line 45 def make_regexp(key) Regexp.new(key.gsub(/\./, "\\.").gsub(/\*/, '[^.]*').gsub(/#/, '.*')) end |
#unbind(exchange, opts = {}) ⇒ Object
39 40 41 42 43 |
# 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 |