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
153 def on_type(type, &block)
154   return unless type == requested_type
155   response[RodaResponseHeaders::CONTENT_TYPE] ||= @scope.opts[:type_routing][:types][type]
156   always(&block)
157 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
170 def real_remaining_path
171   if defined?(@type_routing_extension)
172     "#{super}.#{@type_routing_extension}"
173   else
174     super
175   end
176 end
requested_type()

Returns the data type the client requests.

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