Sha256: cb56c626cee07081460134213cfca2221f258f1582c5108a7e78658542a72c30

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

class Roda
  module RodaPlugins
    # The all_verbs plugin adds methods for http verbs other than
    # get and post.  The following verbs are added, assuming
    # rack handles them: delete, head, options, link, patch, put,
    # trace, unlink.
    #
    # These methods operate just like Roda's default get and post
    # methods other that the http verb used, so using them without
    # any arguments just checks for the request method, while
    # using them with any arguments also checks that the arguments
    # match the full path.
    #
    # Example:
    #
    #   plugin :all_verbs
    #
    #   route do |r|
    #     r.delete
    #       # Handle DELETE
    #     end
    #     r.put do
    #       # Handle PUT
    #     end
    #     r.patch do
    #       # Handle PATCH
    #     end
    #   end
    #
    # The verb methods are defined via metaprogramming, so there
    # isn't documentation for the individual methods created.
    module AllVerbs
      module RequestMethods
        %w'delete head options link patch put trace unlink'.each do |t|
          if ::Rack::Request.method_defined?("#{t}?")
            class_eval(<<-END, __FILE__, __LINE__+1)
              def #{t}(*args, &block)
                _verb(args, &block) if #{t}?
              end
            END
          end
        end
      end
    end

    register_plugin(:all_verbs, AllVerbs)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roda-cj-0.9.3 lib/roda/plugins/all_verbs.rb