Class: Capybara::Poltergeist::Client
- Inherits:
-
Object
- Object
- Capybara::Poltergeist::Client
- Defined in:
- lib/capybara/poltergeist/client.rb
Constant Summary collapse
- PHANTOMJS_SCRIPT =
File.('../client/compiled/main.js', __FILE__)
- PHANTOMJS_VERSION =
'1.4.1'
- PHANTOMJS_NAME =
'phantomjs'
Instance Attribute Summary collapse
-
#inspector ⇒ Object
readonly
Returns the value of attribute inspector.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
Instance Method Summary collapse
- #command ⇒ Object
-
#initialize(port, inspector = nil, path = nil) ⇒ Client
constructor
A new instance of Client.
- #restart ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(port, inspector = nil, path = nil) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 |
# File 'lib/capybara/poltergeist/client.rb', line 15 def initialize(port, inspector = nil, path = nil) @port = port @inspector = inspector @path = path || PHANTOMJS_NAME pid = Process.pid at_exit { stop if Process.pid == pid } end |
Instance Attribute Details
#inspector ⇒ Object (readonly)
Returns the value of attribute inspector.
13 14 15 |
# File 'lib/capybara/poltergeist/client.rb', line 13 def inspector @inspector end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/capybara/poltergeist/client.rb', line 13 def path @path end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
13 14 15 |
# File 'lib/capybara/poltergeist/client.rb', line 13 def pid @pid end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
13 14 15 |
# File 'lib/capybara/poltergeist/client.rb', line 13 def port @port end |
Class Method Details
.start(*args) ⇒ Object
7 8 9 10 11 |
# File 'lib/capybara/poltergeist/client.rb', line 7 def self.start(*args) client = new(*args) client.start client end |
Instance Method Details
#command ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/capybara/poltergeist/client.rb', line 47 def command @command ||= begin parts = [path] if inspector parts << "--remote-debugger-port=#{inspector.port}" parts << "--remote-debugger-autorun=yes" end parts << PHANTOMJS_SCRIPT parts << port parts end end |
#restart ⇒ Object
42 43 44 45 |
# File 'lib/capybara/poltergeist/client.rb', line 42 def restart stop start end |
#start ⇒ Object
24 25 26 27 |
# File 'lib/capybara/poltergeist/client.rb', line 24 def start check_phantomjs_version @pid = Spawn.spawn(*command) end |
#stop ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/capybara/poltergeist/client.rb', line 29 def stop if pid begin Process.kill('TERM', pid) Process.wait(pid) rescue Errno::ESRCH, Errno::ECHILD # Zed's dead, baby end @pid = nil end end |