Module: Roda::RodaPlugins::TypeRouting::RequestMethods
- Defined in:
- lib/roda/plugins/type_routing.rb
Instance Method Summary collapse
-
#on_type(type, &block) ⇒ Object
Yields if the given
typematches the requested data type and halts the request afterwards, returning the result of the block. -
#requested_type ⇒ Object
Returns the data type the client requests.
-
#run(_) ⇒ Object
Add the type routing extension back to the remaining path if it was removed from the path when the application was initialized.
Instance Method Details
#on_type(type, &block) ⇒ Object
Yields if the given type matches the requested data type and halts the request afterwards, returning the result of the block.
147 148 149 150 151 |
# File 'lib/roda/plugins/type_routing.rb', line 147 def on_type(type, &block) return unless type == requested_type response[CONTENT_TYPE_HEADER] ||= @scope.opts[:type_routing][:types][type] always(&block) end |
#requested_type ⇒ Object
Returns the data type the client requests.
154 155 156 157 158 159 160 |
# File 'lib/roda/plugins/type_routing.rb', line 154 def requested_type return @requested_type if defined?(@requested_type) opts = @scope.opts[:type_routing] @requested_type = accept_response_type if opts[:use_header] @requested_type ||= opts[:default_type] end |
#run(_) ⇒ Object
Add the type routing extension back to the remaining path if it was removed from the path when the application was initialized.
165 166 167 168 169 170 |
# File 'lib/roda/plugins/type_routing.rb', line 165 def run(_) if defined?(@type_routing_extension) @remaining_path += ".#{@type_routing_extension}" end super end |