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.7.0'
- PHANTOMJS_NAME =
'phantomjs'
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#phantomjs_options ⇒ Object
readonly
Returns the value of attribute phantomjs_options.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#window_size ⇒ Object
readonly
Returns the value of attribute window_size.
Class Method Summary collapse
Instance Method Summary collapse
- #command ⇒ Object
-
#initialize(port, options = {}) ⇒ Client
constructor
A new instance of Client.
- #restart ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(port, options = {}) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 23 |
# File 'lib/capybara/poltergeist/client.rb', line 15 def initialize(port, = {}) @port = port @path = [:path] || PHANTOMJS_NAME @window_size = [:window_size] || [1024, 768] @phantomjs_options = [:phantomjs_options] || [] pid = Process.pid at_exit { stop if Process.pid == pid } end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/capybara/poltergeist/client.rb', line 13 def path @path end |
#phantomjs_options ⇒ Object (readonly)
Returns the value of attribute phantomjs_options.
13 14 15 |
# File 'lib/capybara/poltergeist/client.rb', line 13 def @phantomjs_options 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 |
#window_size ⇒ Object (readonly)
Returns the value of attribute window_size.
13 14 15 |
# File 'lib/capybara/poltergeist/client.rb', line 13 def window_size @window_size 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
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/capybara/poltergeist/client.rb', line 48 def command @command ||= begin parts = [path] parts.concat parts << PHANTOMJS_SCRIPT parts << port parts.concat window_size parts end end |
#restart ⇒ Object
43 44 45 46 |
# File 'lib/capybara/poltergeist/client.rb', line 43 def restart stop start end |
#start ⇒ Object
25 26 27 28 |
# File 'lib/capybara/poltergeist/client.rb', line 25 def start check_phantomjs_version @pid = Spawn.spawn(*command) end |
#stop ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/capybara/poltergeist/client.rb', line 30 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 |