Sha256: 04a860f8e91e7bdb953c2d04e8b784b8beab6f8fbfc1cb021008597b8da46f23

Contents?: true

Size: 758 Bytes

Versions: 6

Compression:

Stored size: 758 Bytes

Contents

require 'multi_json'

module Leadlight

  class ServiceMiddleware
    def initialize(app, options={})
      @app = app
      @service = options.fetch(:service)
    end

    def call(env)
      env[:leadlight_service] = @service
      env[:request_headers]['Accept'] = default_accept_types
      @app.call(env).on_complete do |env|
        env[:leadlight_representation] = represent(env)
      end
    end

    private

    def default_accept_types
      %w[
        application/json
        text/x-yaml
        application/xml
        application/xhtml+xml
        text/html
        text/plain
      ]
    end

    def represent(env)
      leadlight_request = env[:request].fetch(:leadlight_request)
      leadlight_request.represent(env)
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
leadlight-0.1.0 lib/leadlight/service_middleware.rb
leadlight-0.0.7 lib/leadlight/service_middleware.rb
leadlight-0.0.6 lib/leadlight/service_middleware.rb
leadlight-0.0.5 lib/leadlight/service_middleware.rb
leadlight-0.0.4 lib/leadlight/service_middleware.rb
leadlight-0.0.3 lib/leadlight/service_middleware.rb