module Flammarion::Revelator

@api private @todo This all needs a lot of clean up

Constants

CHROME_PATH

Private Class Methods

browser(name, &block) click to toggle source
# File lib/flammarion/revelator.rb, line 52
def self.browser(name, &block)
  @@browsers << OpenStruct.new(name: name, method:define_method(name, block))
end

Public Instance Methods

open_a_window(options = {}) click to toggle source
# File lib/flammarion/revelator.rb, line 22
def open_a_window(options = {})
  development_mode = Flammarion.development_mode?
  host = "http://localhost:#{server.webrick_port}/"

  @expect_title = options[:title] || "Flammarion"
  url = "#{host}?path=#{@window_id}&port=#{server.port}&title=#{@expect_title}"
  @browser_options = options.merge({url: url, development_mode: development_mode})
  @requested_browser = ENV["FLAMMARION_BROWSER"] || options[:browser]

  @browser = @@browsers.find do |browser|
    next if @requested_browser and browser.name.to_s != @requested_browser
    begin
      __send__(browser.name, @browser_options)
    rescue Exception
      next
    end
  end

  raise SetupError.new("You must have either electron or google-chrome installed and accesible via your path.") unless @browser
end
wait_for_a_connection() click to toggle source

@api private

# File lib/flammarion/revelator.rb, line 44
def wait_for_a_connection
   Timeout.timeout(20) { sleep 0.01 while @sockets.empty? }
 rescue Timeout::Error
   raise SetupError.new("Timed out while waiting for a connecting using #{@browser.name}.")
end

Private Instance Methods

which(cmd) click to toggle source
# File lib/flammarion/revelator.rb, line 119
def which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    end
  end
  return nil
end