Module: Interpol::Sinatra::RequestParamsParser::SinatraOverriddes
- Extended by:
- Forwardable
- Defined in:
- lib/interpol/sinatra/request_params_parser.rb
Class Method Summary collapse
Instance Method Summary collapse
- #params ⇒ Object
-
#process_route(*method_args, &block) ⇒ Object
We cannot access the full params (w/ path params) in a before hook, due to the order that sinatra runs the hooks in relation to route matching.
- #skip_param_parsing! ⇒ Object
- #with_parsed_params ⇒ Object
Class Method Details
.being_processed_by_sinatra?(block) ⇒ Boolean
142 143 144 145 146 147 148 149 |
# File 'lib/interpol/sinatra/request_params_parser.rb', line 142 def self.being_processed_by_sinatra?(block) # In case the block is nil or we're on 1.8 w/o #source_location... # Just assume the route is being processed by sinatra. # It's an exceptional case for it to not be (e.g. NewRelic's # Sinatra hook). return true unless block.respond_to?(:source_location) block.source_location.first.end_with?('sinatra/base.rb') end |
Instance Method Details
#params ⇒ Object
151 152 153 |
# File 'lib/interpol/sinatra/request_params_parser.rb', line 151 def params @_parsed_params || super end |
#process_route(*method_args, &block) ⇒ Object
We cannot access the full params (w/ path params) in a before hook, due to the order that sinatra runs the hooks in relation to route matching.
132 133 134 135 136 137 138 139 140 |
# File 'lib/interpol/sinatra/request_params_parser.rb', line 132 def process_route(*method_args, &block) return super unless SinatraOverriddes.being_processed_by_sinatra?(block) super do |*block_args| with_parsed_params do yield *block_args end end end |
#skip_param_parsing! ⇒ Object
165 166 167 |
# File 'lib/interpol/sinatra/request_params_parser.rb', line 165 def skip_param_parsing! @_skip_param_parsing = true end |
#with_parsed_params ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'lib/interpol/sinatra/request_params_parser.rb', line 155 def with_parsed_params unless @_skip_param_parsing @_parsed_params = request_params_parser.validate_and_parse_params(self) end yield ensure @_parsed_params = nil end |