Class: Rack::Padlock::Phantomjs

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/padlock/phantomjs.rb

Constant Summary collapse

KILL_TIMEOUT =

seconds

20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addresses, binary = nil) ⇒ Phantomjs

Returns a new instance of Phantomjs.



7
8
9
10
11
# File 'lib/rack/padlock/phantomjs.rb', line 7

def initialize(addresses, binary=nil)
  @binary = binary || 'phantomjs'
  @addresses = addresses
  @pid = nil
end

Instance Attribute Details

#binaryObject (readonly)

Returns the value of attribute binary.



5
6
7
# File 'lib/rack/padlock/phantomjs.rb', line 5

def binary
  @binary
end

#pidObject (readonly)

Returns the value of attribute pid.



5
6
7
# File 'lib/rack/padlock/phantomjs.rb', line 5

def pid
  @pid
end

Instance Method Details

#commandObject



13
14
15
16
# File 'lib/rack/padlock/phantomjs.rb', line 13

def command
  js_path = ::File.expand_path('../padlock.js', __FILE__)
  "#{@binary} --ignore-ssl-errors=yes #{js_path} #{@addresses.join(' ')}"
end

#startObject



18
19
20
21
# File 'lib/rack/padlock/phantomjs.rb', line 18

def start
  puts "Starting up phantomjs\n"
  Timeout.timeout(KILL_TIMEOUT) { system(command) }
end