Class: Linzer::Message::Adapter::Abstract Abstract
- Inherits:
-
Object
- Object
- Linzer::Message::Adapter::Abstract
- Defined in:
- lib/linzer/message/adapter/abstract.rb
Overview
Abstract base class for HTTP message adapters.
Adapters provide a unified interface for accessing HTTP message components regardless of the underlying HTTP library. Each adapter implements field retrieval, header access, and signature attachment for a specific HTTP message type.
Direct Known Subclasses
Generic::Request, Generic::Response, Rack::Request, Rack::Response
Instance Method Summary collapse
-
#[](field) ⇒ String, ...
Retrieves a component value from the message.
-
#attach!(signature) ⇒ Object
abstract
Attaches a signature to the underlying HTTP message.
-
#attached_request? ⇒ Boolean
Checks if this response has an attached request.
-
#field?(f) ⇒ Boolean
Checks if a component exists in the message.
-
#header(name) ⇒ String?
abstract
Retrieves a raw header value by name.
-
#initialize(operation, **options) ⇒ Abstract
constructor
A new instance of Abstract.
-
#request? ⇒ Boolean
Checks if this adapter wraps an HTTP request.
-
#response? ⇒ Boolean
Checks if this adapter wraps an HTTP response.
Constructor Details
#initialize(operation, **options) ⇒ Abstract
Returns a new instance of Abstract.
22 23 24 |
# File 'lib/linzer/message/adapter/abstract.rb', line 22 def initialize(operation, **) raise Linzer::Error, "Cannot instantiate an abstract class!" end |
Instance Method Details
#[](field) ⇒ String, ...
Retrieves a component value from the message.
Handles both regular header fields and derived components, including parameter processing (‘;sf`, `;bs`, `;req`, `;key`).
72 73 74 75 76 |
# File 'lib/linzer/message/adapter/abstract.rb', line 72 def [](field) field_id = field.is_a?(FieldId) ? field : parse_field_name(field) return nil if field_id.nil? || field_id.item.nil? retrieve(field_id.item, field_id.derived? ? :derived : :field) end |
#attach!(signature) ⇒ Object
Subclasses must implement this method.
Attaches a signature to the underlying HTTP message.
92 93 94 |
# File 'lib/linzer/message/adapter/abstract.rb', line 92 def attach!(signature) raise Linzer::Error, "Sub-classes are required to implement this method!" end |
#attached_request? ⇒ Boolean
Checks if this response has an attached request.
Attached requests enable the ‘;req` parameter for accessing request fields from a response signature.
44 45 46 |
# File 'lib/linzer/message/adapter/abstract.rb', line 44 def attached_request? response? && !!@attached_request end |
#field?(f) ⇒ Boolean
Checks if a component exists in the message.
52 53 54 |
# File 'lib/linzer/message/adapter/abstract.rb', line 52 def field?(f) !!self[f] end |
#header(name) ⇒ String?
Subclasses must implement this method.
Retrieves a raw header value by name.
83 84 85 |
# File 'lib/linzer/message/adapter/abstract.rb', line 83 def header(name) raise Linzer::Error, "Sub-classes are required to implement this method!" end |
#request? ⇒ Boolean
Checks if this adapter wraps an HTTP request.
28 29 30 |
# File 'lib/linzer/message/adapter/abstract.rb', line 28 def request? self.class.to_s.include?("Request") end |
#response? ⇒ Boolean
Checks if this adapter wraps an HTTP response.
34 35 36 |
# File 'lib/linzer/message/adapter/abstract.rb', line 34 def response? self.class.to_s.include?("Response") end |