module Roda::RodaPlugins::NotAllowed::RequestClassMethods
Public Instance Methods
def_verb_method(mod, verb)
click to toggle source
Define a method named verb
in the given module which will return a 405 response if the method is called with any arguments and the arguments terminally match but the request method does not.
If called without any arguments, check to see if the call is inside a terminal match, and in that case record the request method used.
# File lib/roda/plugins/not_allowed.rb, line 83 def def_verb_method(mod, verb) mod.class_eval(<<-END, __FILE__, __LINE__+1) def #{verb}(*args, &block) if args.empty? @_is_verbs << "#{verb.to_s.upcase}" if @_is_verbs always(&block) if #{verb == :get ? :is_get : verb}? else args << ::Roda::RodaPlugins::Base::RequestMethods::TERM if_match(args) do |*args| if #{verb == :get ? :is_get : verb}? block_result(yield(*args)) throw :halt, response.finish end response.status = 405 response['Allow'] = '#{verb.to_s.upcase}' nil end end end END end