Class: NgrokV1::Client
- Inherits:
-
Object
- Object
- NgrokV1::Client
- Defined in:
- lib/ngrok-v1/client.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ngrok-v1/client.rb', line 5 def initialize( = {}) raise "Failed to find ngrok v1 binary." unless binary_installed? raise "Port number not specified." unless .key?(:port) raise "Protocol not specified." unless .key?(:protocol) @port = [:port] @protocol = [:protocol] @log = nil @pid = nil @uri = nil end |
Instance Method Details
#running? ⇒ Boolean
36 37 38 |
# File 'lib/ngrok-v1/client.rb', line 36 def running? !@pid.nil? end |
#start ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ngrok-v1/client.rb', line 17 def start return if running? @log = Tempfile.new("ngrok-v1") @pid = Process.spawn(execution_string) at_exit { stop } # Ensure process is killed if Ruby exits. @uri = parse_uri! end |
#stop ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ngrok-v1/client.rb', line 28 def stop return unless running? Process.kill("KILL", @pid) @pid = nil end |
#uri ⇒ Object
40 41 42 |
# File 'lib/ngrok-v1/client.rb', line 40 def uri @uri if running? end |