Class: Woodhouse::QueueCriteria

Inherits:
Object
  • Object
show all
Defined in:
lib/woodhouse/queue_criteria.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#criteriaObject (readonly)

Returns the value of attribute criteria.



4
5
6
# File 'lib/woodhouse/queue_criteria.rb', line 4

def criteria
  @criteria
end

#exclusiveObject

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_headersObject



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

#describeObject



22
23
24
# File 'lib/woodhouse/queue_criteria.rb', line 22

def describe
  @criteria.inspect
end

#exclusive?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/woodhouse/queue_criteria.rb', line 46

def exclusive?
  !!exclusive
end

#matches?(args) ⇒ Boolean

Returns:

  • (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_keyObject



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