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.
149 150 151 152 153 |
# File 'lib/roda/plugins/type_routing.rb', line 149 def on_type(type, &block) return unless type == requested_type response['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.
166 167 168 169 170 171 172 |
# File 'lib/roda/plugins/type_routing.rb', line 166 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.
156 157 158 159 160 161 162 |
# File 'lib/roda/plugins/type_routing.rb', line 156 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 |