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. -
#real_remaining_path ⇒ Object
Append the type routing extension back to the path if it was removed before routing.
-
#requested_type ⇒ Object
Returns the data type the client requests.
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 |
#real_remaining_path ⇒ Object
Append the type routing extension back to the path if it was removed before routing.
164 165 166 167 168 169 170 |
# File 'lib/roda/plugins/type_routing.rb', line 164 def real_remaining_path if defined?(@type_routing_extension) "#{super}.#{@type_routing_extension}" else super end 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 |