Sha256: 97dd018e013c4a6332d5ab72b18f85415a56561e7d677861df481e7740caf6f0

Contents?: true

Size: 935 Bytes

Versions: 4

Compression:

Stored size: 935 Bytes

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2018-2023, by Samuel Williams.

module Protocol
	module HTTP
		# All supported HTTP methods
		class Methods
			GET = 'GET'
			POST = 'POST'
			PUT = 'PUT'
			PATCH = 'PATCH'
			DELETE = 'DELETE'
			HEAD = 'HEAD'
			OPTIONS = 'OPTIONS'
			LINK = 'LINK'
			UNLINK = 'UNLINK'
			TRACE = 'TRACE'
			CONNECT = 'CONNECT'
			
			def self.valid?(name)
				const_defined?(name)
			rescue NameError
				# Ruby will raise an exception if the name is not valid for a constant.
				return false
			end
			
			def self.each
				constants.each do |name|
					yield name, const_get(name)
				end
			end
			
			# Use Methods.constants to get all constants.
			self.each do |name, value|
				define_method(name.downcase) do |location, headers = nil, body = nil|
					self.call(
						Request[value, location.to_s, Headers[headers], body]
					)
				end
			end
		end
	end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
protocol-http-0.24.3 lib/protocol/http/methods.rb
protocol-http-0.24.2 lib/protocol/http/methods.rb
protocol-http-0.24.1 lib/protocol/http/methods.rb
protocol-http-0.24.0 lib/protocol/http/methods.rb