class Falcon::Capybara::Wrapper

Implements a wrapper for starting the Falcon server for Capybara.

Public Class Methods

new(scheme = "http") click to toggle source

@parameter scheme [String] The scheme for the server to bind to.

e.g. `http` or `https`.
# File lib/falcon/capybara/wrapper.rb, line 33
def initialize(scheme = "http")
        @scheme = scheme
end

Public Instance Methods

call(rack_app, port, host) click to toggle source

Run the Falcon server hosting the given rack application. @parameter rack_app [Proc] A Rack application. @parameter port [Integer] The port number to bind to. @parameter host [String] The local host to bind to.

# File lib/falcon/capybara/wrapper.rb, line 46
def call(rack_app, port, host)
        require 'async/reactor'
        require 'falcon/server'
        
        Async do |task|
                app = Falcon::Server.middleware(rack_app)
                
                if host == "127.0.0.1"
                        host = "localhost"
                end
                
                endpoint = self.endpoint(host, port)
                
                server = Falcon::Server.new(app, endpoint, protocol: endpoint.protocol, scheme: endpoint.scheme)
                
                Async.logger.debug (self) {"Running server..."}
                server.run
        end
end
endpoint(host, port) click to toggle source

Build a server endpoint using the given scheme.

# File lib/falcon/capybara/wrapper.rb, line 38
def endpoint(host, port)
        Falcon::Endpoint.parse("#{@scheme}://#{host}:#{port}")
end