Class: BrowserMob::Proxy::Server
- Inherits:
-
Object
- Object
- BrowserMob::Proxy::Server
- Defined in:
- lib/browsermob/proxy/server.rb
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #create_proxy ⇒ Object
-
#initialize(path, opts = {}) ⇒ Server
constructor
A new instance of Server.
- #start ⇒ Object
- #stop ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(path, opts = {}) ⇒ Server
Returns a new instance of Server.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/browsermob/proxy/server.rb', line 10 def initialize(path, opts = {}) unless File.exist?(path) raise Errno::ENOENT, path end unless File.executable?(path) raise Errno::EACCES, "not executable: #{path}" end @path = path @port = Integer(opts[:port] || 8080) @process = ChildProcess.new(path, "--port", port.to_s) @process.io.inherit! if opts[:log] end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/browsermob/proxy/server.rb', line 8 def port @port end |
Instance Method Details
#create_proxy ⇒ Object
40 41 42 |
# File 'lib/browsermob/proxy/server.rb', line 40 def create_proxy Client.from url end |
#start ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/browsermob/proxy/server.rb', line 26 def start @process.start sleep 0.1 until listening? pid = Process.pid at_exit { stop if Process.pid == pid } self end |
#stop ⇒ Object
44 45 46 |
# File 'lib/browsermob/proxy/server.rb', line 44 def stop @process.stop if @process.alive? end |
#url ⇒ Object
36 37 38 |
# File 'lib/browsermob/proxy/server.rb', line 36 def url "http://localhost:#{port}" end |