Class: Terminus::Client::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/terminus/client.rb

Direct Known Subclasses

Browser, PhantomJS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.



24
25
26
27
28
29
30
31
32
# File 'lib/terminus/client.rb', line 24

def initialize(options)
  @id        = Faye.random
  @options   = options
  @address   = TCPServer.new(0).addr
  @connector = Connector.new(self)
  @port      = options[:port] || @address[1]
  @terminus  = Terminus.create(:port => @port)
  @browser   = ChildProcess.build(*browser_args)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/terminus/client.rb', line 8

def id
  @id
end

Class Method Details

.debuggerObject



16
17
18
# File 'lib/terminus/client.rb', line 16

def self.debugger
  @process.debugger
end

.save_screenshot(path, options = {}) ⇒ Object



20
21
22
# File 'lib/terminus/client.rb', line 20

def self.save_screenshot(path, options = {})
  @process.save_screenshot(path, options)
end

.start(options = {}) ⇒ Object



10
11
12
13
14
# File 'lib/terminus/client.rb', line 10

def self.start(options = {})
  @process = new(options)
  @process.start
  @process
end

Instance Method Details

#debug(*args) ⇒ Object



34
35
36
# File 'lib/terminus/client.rb', line 34

def debug(*args)
  p args if Terminus.debug
end

#startObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/terminus/client.rb', line 38

def start
  Terminus.ensure_reactor_running
  @terminus.run!

  @browser.start

  Terminus.port = @port
  Terminus.browser = browser_selector

  at_exit { stop }
end

#stopObject



50
51
52
53
54
55
# File 'lib/terminus/client.rb', line 50

def stop
  @terminus.stop!
  @browser.stop
  @browser.poll_for_exit(10)
rescue ChildProcess::TimeoutError
end