Sha256: 61ba53e0bceb8c7edd5e8de4fda7900ac6c9099f09489b1ad1088aeca16e3f55

Contents?: true

Size: 511 Bytes

Versions: 2

Compression:

Stored size: 511 Bytes

Contents

class SiteHub
  module Middleware
    def middlewares
      @middleware ||= []
    end

    def use(middleware_clazz, *args, &block)
      middlewares << [middleware_clazz, args, block|| proc{}]
    end

    def apply_middleware(forward_proxy)
      middlewares.reverse.inject(forward_proxy) do |app, middleware_def|
        middleware = middleware_def[0]
        args = middleware_def[1] || []
        block = middleware_def[2] || proc {}

        middleware.new(app, *args, &block)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sitehub-0.4.2 lib/sitehub/middleware.rb
sitehub-0.4.1 lib/sitehub/middleware.rb