Class: Base
- Inherits:
-
Object
- Object
- Base
- Defined in:
- lib/restclient/multipart.rb
Direct Known Subclasses
Instance Method Summary collapse
- #build_stream(params) ⇒ Object
- #close ⇒ Object
- #escape(v) ⇒ Object
- #headers ⇒ Object
-
#initialize(params) ⇒ Base
constructor
A new instance of Base.
- #read(bytes = nil) ⇒ Object (also: #to_s)
- #rewind ⇒ Object
- #size ⇒ Object (also: #length)
Constructor Details
#initialize(params) ⇒ Base
Returns a new instance of Base.
2 3 4 |
# File 'lib/restclient/multipart.rb', line 2 def initialize(params) build_stream(params) end |
Instance Method Details
#build_stream(params) ⇒ Object
6 7 8 9 |
# File 'lib/restclient/multipart.rb', line 6 def build_stream(params) @stream = StringIO.new(params) @stream.seek(0) end |
#close ⇒ Object
33 34 35 |
# File 'lib/restclient/multipart.rb', line 33 def close @stream.close end |
#escape(v) ⇒ Object
20 21 22 |
# File 'lib/restclient/multipart.rb', line 20 def escape(v) URI.escape(v.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) end |
#headers ⇒ Object
24 25 26 |
# File 'lib/restclient/multipart.rb', line 24 def headers { 'Content-Length' => size.to_s } end |
#read(bytes = nil) ⇒ Object Also known as: to_s
15 16 17 |
# File 'lib/restclient/multipart.rb', line 15 def read(bytes=nil) @stream.read(bytes) end |
#rewind ⇒ Object
11 12 13 |
# File 'lib/restclient/multipart.rb', line 11 def rewind @stream.seek(0) end |
#size ⇒ Object Also known as: length
28 29 30 |
# File 'lib/restclient/multipart.rb', line 28 def size @stream.size end |