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
type
matches 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.
153 154 155 156 157 |
# File 'lib/roda/plugins/type_routing.rb', line 153 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.
170 171 172 173 174 175 176 |
# File 'lib/roda/plugins/type_routing.rb', line 170 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.
160 161 162 163 164 165 166 |
# File 'lib/roda/plugins/type_routing.rb', line 160 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 |