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
131 132 133 134 135 136 137 138 |
# File 'lib/interpol/sinatra/request_params_parser.rb', line 131 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
140 141 142 |
# File 'lib/interpol/sinatra/request_params_parser.rb', line 140 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.
121 122 123 124 125 126 127 128 129 |
# File 'lib/interpol/sinatra/request_params_parser.rb', line 121 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
154 155 156 |
# File 'lib/interpol/sinatra/request_params_parser.rb', line 154 def skip_param_parsing! @_skip_param_parsing = true end |
#with_parsed_params ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/interpol/sinatra/request_params_parser.rb', line 144 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 |