Class: Interpol::Sinatra::RequestParamsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/interpol/sinatra/request_params_parser.rb

Overview

Parses and validates a sinatra params hash based on the endpoint definitions. Note that you use this like a sinatra middleware (using a ‘use` directive in the body of the sinatra class), but it hooks into sinatra differently so that it has access to the params. It’s more like a mix-in, honestly, but we piggyback on ‘use` so that it can take a config block.

Defined Under Namespace

Modules: SinatraOverriddes Classes: SingleRequestParamsParser

Constant Summary collapse

ConfigurationError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(app, &block) ⇒ RequestParamsParser

Returns a new instance of RequestParamsParser.



14
15
16
17
18
# File 'lib/interpol/sinatra/request_params_parser.rb', line 14

def initialize(app, &block)
  @original_app_instance = app
  @config = Configuration.default.customized_duplicate(&block)
  hook_into_app(&block)
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
# File 'lib/interpol/sinatra/request_params_parser.rb', line 20

def call(env)
  @original_app_instance.call(env)
end

#validate_and_parse_params(app) ⇒ Object

Sinatra dups the app before each request, so we need to receive the app instance as an argument here.



28
29
30
31
# File 'lib/interpol/sinatra/request_params_parser.rb', line 28

def validate_and_parse_params(app)
  return unless app.settings.parse_params?
  SingleRequestParamsParser.parse_params(config, app)
end