module Roda::RodaPlugins::TypeRouting::RequestMethods

  1. lib/roda/plugins/type_routing.rb

Methods

Public Instance

  1. on_type
  2. real_remaining_path
  3. requested_type

Public Instance methods

on_type(type, &block)

Yields if the given type matches the requested data type and halts the request afterwards, returning the result of the block.

[show source]
    # File lib/roda/plugins/type_routing.rb
155 def on_type(type, &block)
156   return unless type == requested_type
157   response[RodaResponseHeaders::CONTENT_TYPE] ||= @scope.opts[:type_routing][:types][type]
158   always(&block)
159 end
real_remaining_path()

Append the type routing extension back to the path if it was removed before routing.

[show source]
    # File lib/roda/plugins/type_routing.rb
172 def real_remaining_path
173   if @type_routing_extension
174     "#{super}.#{@type_routing_extension}"
175   else
176     super
177   end
178 end
requested_type()

Returns the data type the client requests.

[show source]
    # File lib/roda/plugins/type_routing.rb
162 def requested_type
163   return @requested_type if @requested_type
164 
165   opts = @scope.opts[:type_routing]
166   @requested_type = accept_response_type if opts[:use_header]
167   @requested_type ||= opts[:default_type]
168 end