Class: Retab::Multipart
- Inherits:
-
Object
- Object
- Retab::Multipart
- Defined in:
- lib/retab/multipart.rb
Overview
A multipart/form-data request body. ‘fields` maps wire field name => value, where each value is either a plain scalar (sent as a text part via `#to_s`) or a `FilePart` (sent as a binary file part).
Defined Under Namespace
Classes: FilePart
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
-
#initialize(fields = {}) ⇒ Multipart
constructor
A new instance of Multipart.
-
#to_form_parts ⇒ Object
Build the ‘[name, value]` pairs net/http’s ‘#set_form` expects.
Constructor Details
#initialize(fields = {}) ⇒ Multipart
Returns a new instance of Multipart.
25 26 27 |
# File 'lib/retab/multipart.rb', line 25 def initialize(fields = {}) @fields = fields end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
23 24 25 |
# File 'lib/retab/multipart.rb', line 23 def fields @fields end |
Instance Method Details
#to_form_parts ⇒ Object
Build the ‘[name, value]` pairs net/http’s ‘#set_form` expects. Binary parts become `[name, io, { filename:, content_type: }]`; scalar parts become `[name, string]`.
32 33 34 35 36 37 38 39 40 |
# File 'lib/retab/multipart.rb', line 32 def to_form_parts @fields.map do |name, value| if value.is_a?(FilePart) [name.to_s, value.io, value.form_opts] else [name.to_s, value.to_s] end end end |