Class: Woodhouse::QueueCriteria
- Inherits:
-
Object
- Object
- Woodhouse::QueueCriteria
- Defined in:
- lib/woodhouse/queue_criteria.rb
Instance Attribute Summary collapse
-
#criteria ⇒ Object
readonly
Returns the value of attribute criteria.
-
#exclusive ⇒ Object
Returns the value of attribute exclusive.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #amqp_headers ⇒ Object
- #describe ⇒ Object
- #exclusive? ⇒ Boolean
-
#initialize(values = {}, flags = nil) ⇒ QueueCriteria
constructor
A new instance of QueueCriteria.
- #matches?(args) ⇒ Boolean
- #queue_key ⇒ Object
Constructor Details
#initialize(values = {}, flags = nil) ⇒ QueueCriteria
Returns a new instance of QueueCriteria.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/woodhouse/queue_criteria.rb', line 7 def initialize(values = {}, flags = nil) flags ||= {} self.exclusive ||= flags[:exclusive] if values.kind_of?(self.class) values = values.criteria end unless values.nil? @criteria = stringify_values(values).freeze end end |
Instance Attribute Details
#criteria ⇒ Object (readonly)
Returns the value of attribute criteria.
4 5 6 |
# File 'lib/woodhouse/queue_criteria.rb', line 4 def criteria @criteria end |
#exclusive ⇒ Object
Returns the value of attribute exclusive.
5 6 7 |
# File 'lib/woodhouse/queue_criteria.rb', line 5 def exclusive @exclusive end |
Instance Method Details
#==(other) ⇒ Object
18 19 20 |
# File 'lib/woodhouse/queue_criteria.rb', line 18 def ==(other) @criteria == other.criteria end |
#amqp_headers ⇒ Object
26 27 28 29 |
# File 'lib/woodhouse/queue_criteria.rb', line 26 def amqp_headers # TODO: needs to be smarter @criteria ? @criteria.merge('x-match' => 'all') : {} end |
#describe ⇒ Object
22 23 24 |
# File 'lib/woodhouse/queue_criteria.rb', line 22 def describe @criteria.inspect end |
#exclusive? ⇒ Boolean
46 47 48 |
# File 'lib/woodhouse/queue_criteria.rb', line 46 def exclusive? !!exclusive end |
#matches?(args) ⇒ Boolean
37 38 39 40 41 42 43 44 |
# File 'lib/woodhouse/queue_criteria.rb', line 37 def matches?(args) return true if @criteria.nil? return false if exclusive? and @criteria.length != args.keys.reject{|k| k =~ /^_/ }.length @criteria.all? do |key, val| args[key] == val end end |
#queue_key ⇒ Object
31 32 33 34 35 |
# File 'lib/woodhouse/queue_criteria.rb', line 31 def queue_key @criteria ? @criteria.map{|k,v| "#{k.downcase}_#{v.downcase}" }.join("_") : "" end |