class Phantomjs::Helper

Constants

BUCKET_URL
VERSION

Public Instance Methods

binary_path() click to toggle source
# File lib/phantomjs/helper.rb, line 46
def binary_path
  if platform == 'windows'
    File.join install_dir, 'phantomjs.exe'
  else
    File.join install_dir, 'phantomjs'
  end
end
download(hit_network=false) click to toggle source
# File lib/phantomjs/helper.rb, line 22
def download(hit_network=false)
  return if File.exists?(binary_path) && !hit_network
  url = download_url
  filename = File.basename url
  FileUtils.mkdir_p install_dir
  Dir.chdir install_dir do
    FileUtils.rm_f filename
    File.open(filename, 'wb') do |saved_file|
      URI.parse(url).open('rb',{:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE}) do |read_file|
        saved_file.write(read_file.read)
      end
    end
    raise "Could not download #{url}" unless File.exists? filename
    Extractor.extract(filename, binary_path)
    FileUtils.rm_f filename
  end
  raise "Could not unzip #{filename} to get #{binary_path}" unless File.exists? binary_path
  FileUtils.chmod 'ugo+rx', binary_path
end
remove() click to toggle source
# File lib/phantomjs/helper.rb, line 42
def remove
  FileUtils.rm binary_path
end
run(*args) click to toggle source
# File lib/phantomjs/helper.rb, line 13
def run(*args)
  download
  exec binary_path, *args
end
update() click to toggle source
# File lib/phantomjs/helper.rb, line 18
def update
  download true
end

Private Instance Methods

download_url() click to toggle source
# File lib/phantomjs/helper.rb, line 60
def download_url
  BitbucketDownloadParser.new(driver_name, url: BUCKET_URL).newest_download
end
driver_name() click to toggle source
# File lib/phantomjs/helper.rb, line 56
def driver_name
  /phantomjs-.*-#{platform}/
end
home_dir() click to toggle source
# File lib/phantomjs/helper.rb, line 79
def home_dir
  ENV['HOME']
end
install_dir() click to toggle source
# File lib/phantomjs/helper.rb, line 64
def install_dir
  File.expand_path File.join(home_dir, '.phantomjs-helper', platform)
end
platform() click to toggle source
# File lib/phantomjs/helper.rb, line 68
def platform
  case RbConfig::CONFIG['host_os']
    when /linux/ then
      RbConfig::CONFIG['host_cpu'] =~ /x86_64|amd64/ ? 'linux-x86_64' : 'linux-i686'
    when /darwin/ then
      'macosx'
    else
      'windows'
  end
end