module Kopflos

heavily inspired by selenium-client

https://github.com/jodell/selenium-client/blob/da0f3dfbc05a6377c0cada09a3d650daf1261415/lib/xvfb/xvfb.rb

Constants

EnvVar

Public Class Methods

disabled_by_env_variable?() click to toggle source
# File lib/kopflos.rb, line 46
def self.disabled_by_env_variable?
  %w(false disabled 0 disable no).include?(ENV[EnvVar].to_s)
end
disabled_by_switch_file?() click to toggle source
# File lib/kopflos.rb, line 50
def self.disabled_by_switch_file?
  File.exists?( switch_file_path )
end
log(message) click to toggle source
# File lib/kopflos.rb, line 58
def self.log(message)
  if ENV['LOG']
    STDERR.puts "#{self}: #{message}"
  end
end
reset!() click to toggle source
# File lib/kopflos.rb, line 41
def self.reset!
  stop
  @server = nil
end
running?() click to toggle source
# File lib/kopflos.rb, line 37
def self.running?
  @server && @server.running?
end
start(opts={}) click to toggle source
# File lib/kopflos.rb, line 8
def self.start(opts={})
  if disabled_by_env_variable?
    log "disabled through environment variable #{EnvVar} (set to anything else than 'false' or '0')"
    return
  end
  if disabled_by_switch_file?
    log "disabled through switch file #{switch_file_path} (unlink to hide the frakkin browser windows again)"
    return
  end
  if running?
    unless opts[:reuse]
      raise AlreadyRunning, "there is already a server running: #{@server}"
    end
  else
    @server = Xvfb.new(opts)
    @server.start
    @server
  end
rescue Xvfb::NotSupported => e
  log "your platform is not supported (yet): #{RUBY_PLATFORM}"
end
stop() click to toggle source
# File lib/kopflos.rb, line 30
def self.stop
  if running?
    @server.stop
    @server = nil
  end
end
switch_file_path() click to toggle source
# File lib/kopflos.rb, line 54
def self.switch_file_path
  'kopflos_disabled'
end