Parent

Class/Module Index [+]

Quicksearch

Grape::Middleware::Base

Attributes

app[R]
env[R]
options[R]

Public Class Methods

new(app, options = {}) click to toggle source

@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

Public Instance Methods

after() click to toggle source

@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 36
def after
end
before() click to toggle source

@abstract Called before the application is called in the middleware lifecycle.

# File lib/grape/middleware/base.rb, line 30
def before
end
call(env) click to toggle source
# File lib/grape/middleware/base.rb, line 17
def call(env)
  dup.call!(env)
end
call!(env) click to toggle source
# File lib/grape/middleware/base.rb, line 21
def call!(env)
  @env = env
  before
  @app_response = @app.call(@env)
  after || @app_response
end
content_type() click to toggle source
# File lib/grape/middleware/base.rb, line 51
def content_type
  content_type_for(env['api.format'] || options[:format]) || 'text/html'
end
content_type_for(format) click to toggle source
# File lib/grape/middleware/base.rb, line 43
def content_type_for(format)
  HashWithIndifferentAccess.new(content_types)[format]
end
content_types() click to toggle source
# File lib/grape/middleware/base.rb, line 47
def content_types
  ContentTypes.content_types_for(options[:content_types])
end
default_options() click to toggle source
# File lib/grape/middleware/base.rb, line 13
def default_options
  {}
end
mime_types() click to toggle source
# File lib/grape/middleware/base.rb, line 55
def mime_types
  content_types.each_with_object({}) { |(k, v), types_without_params|
    types_without_params[k] = v.split(';').first
  }.invert
end
response() click to toggle source
# File lib/grape/middleware/base.rb, line 39
def response
  Rack::Response.new(@app_response)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.