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.
155 156 157 158 159 |
# File 'lib/roda/plugins/type_routing.rb', line 155 def on_type(type, &block) return unless type == requested_type response[RodaResponseHeaders::CONTENT_TYPE] ||= @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.
172 173 174 175 176 177 178 |
# File 'lib/roda/plugins/type_routing.rb', line 172 def real_remaining_path if @type_routing_extension "#{super}.#{@type_routing_extension}" else super end end |
#requested_type ⇒ Object
Returns the data type the client requests.
162 163 164 165 166 167 168 |
# File 'lib/roda/plugins/type_routing.rb', line 162 def requested_type return @requested_type if @requested_type opts = @scope.opts[:type_routing] @requested_type = accept_response_type if opts[:use_header] @requested_type ||= opts[:default_type] end |