Class: TwilioRubyWrapper::QueueCondition

Inherits:
Object
  • Object
show all
Defined in:
lib/twilio_ruby_wrapper/queue_condition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queues:, condition:) ⇒ QueueCondition

Returns a new instance of QueueCondition.



5
6
7
8
9
10
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 5

def initialize(queues: , condition: )
  @condition = condition
  @page_number = 0
  @page_size = 50
  @queues = queues
end

Instance Attribute Details

#page_numberObject

Returns the value of attribute page_number.



3
4
5
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 3

def page_number
  @page_number
end

#page_sizeObject

Returns the value of attribute page_size.



3
4
5
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 3

def page_size
  @page_size
end

#queuesObject

Returns the value of attribute queues.



3
4
5
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 3

def queues
  @queues
end

Instance Method Details

#find_by(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 33

def find_by(*args)
  hash = args.first

  if !(Hash === hash) || hash.values.any? {|v| v.nil? || Array === v || Hash === v } || hash.size >= 2
    raise
  end

  key = hash.keys.first
  value = build_value(hash[key], key)

  queue_set = @queues.list(page: @page_number, page_size: @page_size)
  t = nil
  until queue_set.empty? do
    t = queue_set.select {|queue| @condition[value][build_value(queue.send(key), key)] }.first
    break unless t.nil?
    queue_set = queue_set.next_page
  end
  
  t
end

#where(*args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 12

def where(*args)
  hash = args.first

  if !(Hash === hash) || hash.values.any? {|v| v.nil? || Array === v || Hash === v } || hash.size >= 2
    raise
  end

  key = hash.keys.first
  value = build_value(hash[key], key)

  queues = []
  queue_set = @queues.list(page: @page_number, page_size: @page_size)
  until queue_set.empty? do
    t = queue_set.select {|queue| @condition[value][build_value(queue.send(key), key)] }
    queues.concat(t) unless t.empty?
    queue_set = queue_set.next_page
  end
  
  queues
end