Sha256: 6e5c67c9918745a43b9bf3919b7d9f811ade1498783970f5852974d4f40573b9

Contents?: true

Size: 1.1 KB

Versions: 14

Compression:

Stored size: 1.1 KB

Contents

class App

  def self.running
    @running ? true : false
  end

  def self.port
    ENV['PORT'] || 5000
  end

  def self.ws_port
    ENV['WS_PORT'] || 8080
  end

  def self.websocketio_url
    "ws://localhost:#{ws_port}"
  end

  def self.pid_file
    ENV['PID_FILE'] || "/tmp/sinatra-websocketio-testapp.pid"
  end

  def self.app_dir
    File.expand_path 'app', File.dirname(__FILE__)
  end

  def self.pid
    return unless @running
    File.open(pid_file) do |f|
      pid = f.gets.strip.to_i
      return pid if pid > 0
    end
    return
  end

  def self.start
    return if @running
    File.delete pid_file if File.exists? pid_file
    Thread.new do
      IO::popen "cd #{app_dir} && PID_FILE=#{pid_file} WS_PORT=#{ws_port} rackup config.ru -p #{port} > /dev/null 2>&1"
    end
    @running = true
    100.times do
      if File.exists? pid_file
        sleep 1
        return true
      end
      sleep 0.1
    end
    @running = false
    return false
  end

  def self.stop
    return unless @running
    system "kill #{pid}"
    File.delete pid_file if File.exists? pid_file
    @running = false
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sinatra-websocketio-0.2.7 test/app.rb
sinatra-websocketio-0.2.6 test/app.rb
sinatra-websocketio-0.2.5 test/app.rb
sinatra-websocketio-0.2.4 test/app.rb
sinatra-websocketio-0.2.3 test/app.rb
sinatra-websocketio-0.2.2 test/app.rb
sinatra-websocketio-0.2.1 test/app.rb
sinatra-websocketio-0.2.0 test/app.rb
sinatra-websocketio-0.1.7 test/app.rb
sinatra-websocketio-0.1.6 test/app.rb
sinatra-websocketio-0.1.5 test/app.rb
sinatra-websocketio-0.1.4 test/app.rb
sinatra-websocketio-0.1.3 test/app.rb
sinatra-websocketio-0.1.2 test/app.rb