Sha256: 94abb738dd4bfbb3a60e90458c6d1b3f06abd991a686a9eaf5af2f4de5c1c0d9

Contents?: true

Size: 1.41 KB

Versions: 27

Compression:

Stored size: 1.41 KB

Contents

# frozen-string-literal: true

#
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|
          # :nocov:
          if ::Rack::Request.method_defined?("#{verb}?")
          # :nocov:
            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

27 entries across 27 versions & 1 rubygems

Version Path
roda-3.59.0 lib/roda/plugins/all_verbs.rb
roda-3.58.0 lib/roda/plugins/all_verbs.rb
roda-3.57.0 lib/roda/plugins/all_verbs.rb
roda-3.56.0 lib/roda/plugins/all_verbs.rb
roda-3.55.0 lib/roda/plugins/all_verbs.rb
roda-3.54.0 lib/roda/plugins/all_verbs.rb
roda-3.53.0 lib/roda/plugins/all_verbs.rb
roda-3.52.0 lib/roda/plugins/all_verbs.rb
roda-3.51.0 lib/roda/plugins/all_verbs.rb
roda-3.50.0 lib/roda/plugins/all_verbs.rb
roda-3.49.0 lib/roda/plugins/all_verbs.rb
roda-3.48.0 lib/roda/plugins/all_verbs.rb
roda-3.47.0 lib/roda/plugins/all_verbs.rb
roda-3.46.0 lib/roda/plugins/all_verbs.rb
roda-3.45.0 lib/roda/plugins/all_verbs.rb
roda-3.44.0 lib/roda/plugins/all_verbs.rb
roda-3.43.1 lib/roda/plugins/all_verbs.rb
roda-3.43.0 lib/roda/plugins/all_verbs.rb
roda-3.42.0 lib/roda/plugins/all_verbs.rb
roda-3.41.0 lib/roda/plugins/all_verbs.rb