Class: RSpecRayo::RayoDriver

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-rayo/driver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ RayoDriver

Returns a new instance of RayoDriver.



7
8
9
10
11
12
13
14
15
16
# File 'lib/rspec-rayo/driver.rb', line 7

def initialize(options)
  @calls            = {}
  @call_queue       = Queue.new
  @queue_timeout    = options.delete(:queue_timeout) || 5
  @write_timeout    = options.delete(:write_timeout) || 5
  @threads          = []
  @connection_latch = CountDownLatch.new 1

  initialize_punchblock options
end

Instance Attribute Details

#call_queueObject (readonly)

Returns the value of attribute call_queue.



5
6
7
# File 'lib/rspec-rayo/driver.rb', line 5

def call_queue
  @call_queue
end

#callsObject (readonly)

Returns the value of attribute calls.



5
6
7
# File 'lib/rspec-rayo/driver.rb', line 5

def calls
  @calls
end

Instance Method Details

#cleanup_callsObject



26
27
28
29
30
31
# File 'lib/rspec-rayo/driver.rb', line 26

def cleanup_calls
  @calls.each_pair do |call_id, call|
    call.hangup unless call.status == :finished
  end
  @calls = {}
end

#dial(options) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/rspec-rayo/driver.rb', line 33

def dial(options)
  new_call.tap do |call|
    dial = call.dial options
    call.call_id = dial.call_id
    @calls[call.call_id] = call
  end
end

#get_callObject



22
23
24
# File 'lib/rspec-rayo/driver.rb', line 22

def get_call
  Timeout::timeout(@queue_timeout) { @call_queue.pop }
end

#wait_for_connection(timeout = nil) ⇒ Object



18
19
20
# File 'lib/rspec-rayo/driver.rb', line 18

def wait_for_connection(timeout = nil)
  @connection_latch.wait timeout
end