Class: Praxis::MultipartPart
- Inherits:
-
Object
- Object
- Praxis::MultipartPart
- Defined in:
- lib/praxis/multipart/part.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#headers ⇒ Object
Returns the value of attribute headers.
Instance Method Summary collapse
-
#content_type ⇒ MediaTypeIdentifier
Determine the content type of this response.
-
#content_type=(identifier) ⇒ String
Set the content type for this response.
- #encode! ⇒ Object
-
#initialize(body, headers = {}, filename: nil) ⇒ MultipartPart
constructor
A new instance of MultipartPart.
- #status ⇒ Object
Constructor Details
#initialize(body, headers = {}, filename: nil) ⇒ MultipartPart
Returns a new instance of MultipartPart.
8 9 10 11 12 |
# File 'lib/praxis/multipart/part.rb', line 8 def initialize(body, headers={}, filename: nil) @body = body @headers = headers @filename = filename end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/praxis/multipart/part.rb', line 4 def body @body end |
#filename ⇒ Object
Returns the value of attribute filename.
6 7 8 |
# File 'lib/praxis/multipart/part.rb', line 6 def filename @filename end |
#headers ⇒ Object
Returns the value of attribute headers.
5 6 7 |
# File 'lib/praxis/multipart/part.rb', line 5 def headers @headers end |
Instance Method Details
#content_type ⇒ MediaTypeIdentifier
Determine the content type of this response.
17 18 19 |
# File 'lib/praxis/multipart/part.rb', line 17 def content_type MediaTypeIdentifier.load(headers['Content-Type']).freeze end |
#content_type=(identifier) ⇒ String
TODO:
DRY this out (also used in Response)
Set the content type for this response.
26 27 28 |
# File 'lib/praxis/multipart/part.rb', line 26 def content_type=(identifier) headers['Content-Type'] = MediaTypeIdentifier.load(identifier).to_s end |
#encode! ⇒ Object
34 35 36 37 38 39 |
# File 'lib/praxis/multipart/part.rb', line 34 def encode! case @body when Hash, Array @body = JSON.pretty_generate(@body) end end |
#status ⇒ Object
30 31 32 |
# File 'lib/praxis/multipart/part.rb', line 30 def status @headers['Status'].to_i end |