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
 84 def is(*args)
 85   super(*args) do
 86     begin
 87       is_verbs = @_is_verbs = []
 88 
 89       ret = if args.empty?
 90         yield
 91       else
 92         yield(*captures)
 93       end
 94 
 95       unless is_verbs.empty?
 96         method_not_allowed(is_verbs.join(', '))
 97       end
 98 
 99       ret
100     ensure
101       @_is_verbs = nil
102     end
103   end
104 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
108 def root
109   super
110   if @remaining_path == "/"  && !is_get?
111     always{method_not_allowed("GET")}
112   end
113 end