Class: Wants::ValidateAcceptsMiddleware
- Inherits:
-
Object
- Object
- Wants::ValidateAcceptsMiddleware
- Defined in:
- lib/wants/validate_accepts_middleware.rb
Constant Summary collapse
- DEFAULT_ON_NOT_ACCEPTABLE =
lambda do |env| [ 406, { 'Content-Type' => 'text/plain', 'Content-Length' => '14' }, [ 'Not Acceptable' ] ] end
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options) ⇒ ValidateAcceptsMiddleware
constructor
A new instance of ValidateAcceptsMiddleware.
Constructor Details
#initialize(app, options) ⇒ ValidateAcceptsMiddleware
Returns a new instance of ValidateAcceptsMiddleware.
17 18 19 20 21 22 23 24 |
# File 'lib/wants/validate_accepts_middleware.rb', line 17 def initialize(app, ) @app = app @mime_types = [:mime_types] raise ArgumentError.new("#{self.class} requires option :mime_types") unless @mime_types @on_not_acceptable = [:on_not_acceptable] || DEFAULT_ON_NOT_ACCEPTABLE end |
Instance Method Details
#call(env) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/wants/validate_accepts_middleware.rb', line 26 def call(env) if MatchResult.new(env['HTTP_ACCEPT'], @mime_types).present? @app.call(env) else @on_not_acceptable.call(env) end end |