Class: Nestful::Formats::MultipartFormat
- Defined in:
- lib/nestful/formats/multipart_format.rb
Constant Summary collapse
- EOL =
"\r\n"
Instance Attribute Summary collapse
-
#boundary ⇒ Object
readonly
Returns the value of attribute boundary.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #decode(body) ⇒ Object
- #encode(params, options = nil) ⇒ Object
-
#initialize(*args) ⇒ MultipartFormat
constructor
A new instance of MultipartFormat.
- #mime_type ⇒ Object
Methods inherited from Format
Constructor Details
#initialize(*args) ⇒ MultipartFormat
Returns a new instance of MultipartFormat.
10 11 12 13 14 15 |
# File 'lib/nestful/formats/multipart_format.rb', line 10 def initialize(*args) super @boundary = ActiveSupport::SecureRandom.hex(10) @stream = Tempfile.new("nf.#{rand(1000)}") @stream.binmode end |
Instance Attribute Details
#boundary ⇒ Object (readonly)
Returns the value of attribute boundary.
8 9 10 |
# File 'lib/nestful/formats/multipart_format.rb', line 8 def boundary @boundary end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
8 9 10 |
# File 'lib/nestful/formats/multipart_format.rb', line 8 def stream @stream end |
Instance Method Details
#decode(body) ⇒ Object
29 30 31 |
# File 'lib/nestful/formats/multipart_format.rb', line 29 def decode(body) body end |
#encode(params, options = nil) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/nestful/formats/multipart_format.rb', line 21 def encode(params, = nil) to_multipart(params) stream.write("--" + boundary + "--" + EOL) stream.flush stream.rewind stream end |
#mime_type ⇒ Object
17 18 19 |
# File 'lib/nestful/formats/multipart_format.rb', line 17 def mime_type %Q{multipart/form-data; boundary=#{boundary}} end |