module Roda::RodaPlugins::NotAllowed::RequestMethods

  1. lib/roda/plugins/not_allowed.rb

Methods

Public Instance

  1. is
  2. root

Public Instance methods

is(*args)

Keep track of verb calls inside the block. If there are any verb calls inside the block, but the block returned, assume that the verb calls inside the block did not match, and since there was already a successful terminal match, the request method must not be allowed, so return a 405 response in that case.

[show source]
    # File lib/roda/plugins/not_allowed.rb
 86 def is(*args)
 87   super(*args) do
 88     begin
 89       is_verbs = @_is_verbs = []
 90 
 91       ret = if args.empty?
 92         yield
 93       else
 94         yield(*captures)
 95       end
 96 
 97       unless is_verbs.empty?
 98         method_not_allowed(is_verbs.join(', '))
 99       end
100 
101       ret
102     ensure
103       @_is_verbs = nil
104     end
105   end
106 end
root()

Treat r.root similar to r.get '', using a 405 response for non-GET requests.

[show source]
    # File lib/roda/plugins/not_allowed.rb
110 def root
111   super
112   if @remaining_path == "/"  && !is_get?
113     always{method_not_allowed("GET")}
114   end
115 end