@param [Rack Application] app The standard argument for a Rack middleware. @param [Hash] options A hash of options, simply stored for use by subclasses.
# File lib/grape/middleware/base.rb, line 8 def initialize(app, options = {}) @app = app @options = default_options.merge(options) end
@abstract Called after the application is called in the middleware lifecycle. @return [Response, nil] a Rack SPEC response or nil to call the application afterwards.
# File lib/grape/middleware/base.rb, line 34 def after; end
@abstract Called before the application is called in the middleware lifecycle.
# File lib/grape/middleware/base.rb, line 30 def before; end
# File lib/grape/middleware/base.rb, line 17 def call(env) dup.call!(env) end
# File lib/grape/middleware/base.rb, line 21 def call!(env) @env = env before @app_response = @app.call(@env) after || @app_response end
# File lib/grape/middleware/base.rb, line 52 def content_type content_type_for(env['api.format'] || options[:format]) || 'text/html' end
# File lib/grape/middleware/base.rb, line 44 def content_type_for(format) HashWithIndifferentAccess.new(content_types)[format] end
# File lib/grape/middleware/base.rb, line 48 def content_types ContentTypes.content_types_for(options[:content_types]) end
# File lib/grape/middleware/base.rb, line 13 def default_options {} end
# File lib/grape/middleware/base.rb, line 56 def mime_types content_types.invert end
# File lib/grape/middleware/base.rb, line 36 def request Grape::Request.new(self.env) end
# File lib/grape/middleware/base.rb, line 40 def response Rack::Response.new(@app_response) end