Class: SpecForge::HTTP::Verb

Inherits:
Object
  • Object
show all
Defined in:
lib/spec_forge/http/verb.rb

Overview

Represents an HTTP verb (method)

This class provides a type-safe way to work with HTTP methods, with predefined constants for common verbs like GET, POST, etc.

Examples:

Using predefined verbs

HTTP::Verb::GET    # => #<HTTP::Verb::Get @name="GET">
HTTP::Verb::POST   # => #<HTTP::Verb::Post @name="POST">

Checking verb types

verb = HTTP::Verb::POST
verb.post?   # => true
verb.get?    # => false

Defined Under Namespace

Classes: Delete, Get, Patch, Post, Put

Constant Summary collapse

DELETE =

A predefined DELETE verb instance for HTTP method usage

Returns:

  • (Verb::Delete)

    A singleton instance representing the HTTP DELETE method

See Also:

Delete.new
GET =

A predefined GET verb instance for HTTP method usage

Returns:

  • (Verb::Get)

    A singleton instance representing the HTTP GET method

See Also:

Get.new
PATCH =

A predefined PATCH verb instance for HTTP method usage

Returns:

  • (Verb::Patch)

    A singleton instance representing the HTTP PATCH method

See Also:

Patch.new
POST =

A predefined POST verb instance for HTTP method usage

Returns:

  • (Verb::Post)

    A singleton instance representing the HTTP POST method

See Also:

Post.new
PUT =

A predefined PUT verb instance for HTTP method usage

Returns:

  • (Verb::Put)

    A singleton instance representing the HTTP PUT method

See Also:

Put.new
VERBS =

All HTTP verbs as a lookup hash

Returns:

  • (Hash<Symbol, Verb>)
{
  delete: DELETE,
  get: GET,
  patch: PATCH,
  post: POST,
  put: PUT
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from(name) ⇒ Verb?

Retrieves the corresponding Verb instance based on the provided HTTP name

Parameters:

  • name (String, Symbol)

    The HTTP name to look up (case-insensitive)

Returns:

  • (Verb, nil)

    The corresponding Verb instance, or nil if not found



126
127
128
129
130
# File 'lib/spec_forge/http/verb.rb', line 126

def self.from(name)
  return name if name.is_a?(Verb)

  VERBS[name.downcase.to_sym]
end

Instance Method Details

#==(other) ⇒ Boolean

Returns if this Verb name matches another Verb's name, or the name as a String or Symbol

Parameters:

  • other (Object)

    The thing to check against this object

Returns:

  • (Boolean)


140
141
142
143
144
145
146
147
148
149
# File 'lib/spec_forge/http/verb.rb', line 140

def ==(other)
  case other
  when Verb
    name == other.name
  when String, Symbol
    self == self.class.from(other)
  else
    false
  end
end

#delete?Boolean

Returns if this Verb is a DELETE

Returns:

  • (Boolean)


160
161
162
# File 'lib/spec_forge/http/verb.rb', line 160

def delete?
  name == "DELETE"
end

#get?Boolean

Returns if this Verb is a GET

Returns:

  • (Boolean)


169
170
171
# File 'lib/spec_forge/http/verb.rb', line 169

def get?
  name == "GET"
end

#patch?Boolean

Returns if this Verb is a PATCH

Returns:

  • (Boolean)


178
179
180
# File 'lib/spec_forge/http/verb.rb', line 178

def patch?
  name == "PATCH"
end

#post?Boolean

Returns if this Verb is a POST

Returns:

  • (Boolean)


187
188
189
# File 'lib/spec_forge/http/verb.rb', line 187

def post?
  name == "POST"
end

#put?Boolean

Returns if this Verb is a PUT

Returns:

  • (Boolean)


196
197
198
# File 'lib/spec_forge/http/verb.rb', line 196

def put?
  name == "PUT"
end