Class: Apiwork::Request
- Inherits:
-
Object
- Object
- Apiwork::Request
- Defined in:
- lib/apiwork/request.rb
Overview
Immutable value object representing a request.
Encapsulates query and body parameters. Transformations return new instances, preserving immutability.
Instance Attribute Summary collapse
-
#body ⇒ Hash
readonly
The body for this request.
- #query ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(body:, query:) ⇒ Request
constructor
Creates a new request context.
-
#transform {|Hash| ... } ⇒ Request
Transforms both query and body with the same block.
-
#transform_body {|Hash| ... } ⇒ Request
Transforms only the body.
-
#transform_query {|Hash| ... } ⇒ Request
Transforms only the query.
Constructor Details
#initialize(body:, query:) ⇒ Request
Creates a new request context.
38 39 40 41 |
# File 'lib/apiwork/request.rb', line 38 def initialize(body:, query:) @query = query @body = body end |
Instance Attribute Details
#body ⇒ Hash (readonly)
The body for this request.
28 29 30 |
# File 'lib/apiwork/request.rb', line 28 def body @body end |
Instance Method Details
#transform {|Hash| ... } ⇒ Request
Transforms both query and body with the same block.
51 52 53 |
# File 'lib/apiwork/request.rb', line 51 def transform self.class.new(body: yield(body), query: yield(query)) end |
#transform_body {|Hash| ... } ⇒ Request
Transforms only the body.
75 76 77 |
# File 'lib/apiwork/request.rb', line 75 def transform_body self.class.new(body: yield(body), query: query) end |
#transform_query {|Hash| ... } ⇒ Request
Transforms only the query.
63 64 65 |
# File 'lib/apiwork/request.rb', line 63 def transform_query self.class.new(body: body, query: yield(query)) end |