Sha256: f9e00cb7c777f35ad2f150bca0874f33b3cb9ab0d86924feb6907e70b5f0b2b5

Contents?: true

Size: 778 Bytes

Versions: 10

Compression:

Stored size: 778 Bytes

Contents

module Lita
  # A wrapper around a handler's HTTP route callbacks that sets up the request and response.
  # @api private
  # @since 4.0.0
  class HTTPCallback
    # @param handler_class [Lita::Handler] The handler defining the callback.
    # @param callback [Proc] The callback.
    def initialize(handler_class, callback)
      @handler_class = handler_class
      @callback = callback
    end

    # Call the Rack endpoint with a standard environment hash.
    def call(env)
      request = Rack::Request.new(env)
      response = Rack::Response.new

      if request.head?
        response.status = 204
      else
        handler = @handler_class.new(env["lita.robot"])

        @callback.call(handler, request, response)
      end

      response.finish
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
lita-4.2.1 lib/lita/http_callback.rb
lita-4.2.0 lib/lita/http_callback.rb
lita-4.1.0 lib/lita/http_callback.rb
lita-4.0.4 lib/lita/http_callback.rb
lita-4.0.3 lib/lita/http_callback.rb
lita-4.0.2 lib/lita/http_callback.rb
lita-4.0.1 lib/lita/http_callback.rb
lita-4.0.0 lib/lita/http_callback.rb
lita-4.0.0.rc2 lib/lita/http_callback.rb
lita-4.0.0.rc1 lib/lita/http_callback.rb