Module: Roda::RodaPlugins::NotAllowed::RequestMethods

Defined in:
lib/roda/plugins/not_allowed.rb

Instance Method Summary collapse

Instance Method Details

#is(*args) ⇒ Object

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.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/roda/plugins/not_allowed.rb', line 84

def is(*args)
  super(*args) do
    begin
      is_verbs = @_is_verbs = []

      ret = if args.empty?
        yield
      else
        yield(*captures)
      end

      unless is_verbs.empty?
        method_not_allowed(is_verbs.join(', '))
      end

      ret
    ensure
      @_is_verbs = nil
    end
  end
end

#rootObject

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



108
109
110
111
112
113
# File 'lib/roda/plugins/not_allowed.rb', line 108

def root
  super
  if @remaining_path == "/"  && !is_get?
    always{method_not_allowed("GET")}
  end
end