Sha256: 81747d671babc1bfa3c4cf3f8325e13e4327f4ecd8a5eaaf7371980037a04957

Contents?: true

Size: 1.33 KB

Versions: 13

Compression:

Stored size: 1.33 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, 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 do
    #       # 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 |verb|
          if ::Rack::Request.method_defined?("#{verb}?")
            class_eval(<<-END, __FILE__, __LINE__+1)
              def #{verb}(*args, &block)
                _verb(args, &block) if #{verb}?
              end
            END
          end
        end
      end
    end

    register_plugin(:all_verbs, AllVerbs)
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
roda-2.9.0 lib/roda/plugins/all_verbs.rb
roda-2.8.0 lib/roda/plugins/all_verbs.rb
roda-2.7.0 lib/roda/plugins/all_verbs.rb
roda-2.6.0 lib/roda/plugins/all_verbs.rb
roda-2.5.1 lib/roda/plugins/all_verbs.rb
roda-2.5.0 lib/roda/plugins/all_verbs.rb
roda-2.4.0 lib/roda/plugins/all_verbs.rb
roda-2.3.0 lib/roda/plugins/all_verbs.rb
roda-2.2.0 lib/roda/plugins/all_verbs.rb
roda-2.1.0 lib/roda/plugins/all_verbs.rb
roda-2.0.0 lib/roda/plugins/all_verbs.rb
roda-1.3.0 lib/roda/plugins/all_verbs.rb
roda-1.2.0 lib/roda/plugins/all_verbs.rb