Class: Interpol::Sinatra::RequestParamsParser
- Inherits:
-
Object
- Object
- Interpol::Sinatra::RequestParamsParser
- 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: SinatraOverrides Classes: SingleRequestParamsParser
Constant Summary collapse
- ConfigurationError =
Class.new(StandardError)
Instance Method Summary collapse
- #call(env) ⇒ Object
- #endpoint_parsers ⇒ Object
-
#initialize(app, &block) ⇒ RequestParamsParser
constructor
A new instance of RequestParamsParser.
- #inspect ⇒ Object
-
#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.
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 |
#endpoint_parsers ⇒ Object
33 34 35 36 37 |
# File 'lib/interpol/sinatra/request_params_parser.rb', line 33 def endpoint_parsers @endpoint_parsers ||= Hash.new do |hash, endpoint| hash[endpoint] = Interpol::RequestParamsParser.new(endpoint, @config) end end |
#inspect ⇒ Object
39 40 41 |
# File 'lib/interpol/sinatra/request_params_parser.rb', line 39 def inspect "#<#{self.class.name}>" 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, endpoint_parsers) end |