Class: Alipan::Adapter
- Inherits:
-
Object
- Object
- Alipan::Adapter
- Defined in:
- lib/alipan/adapter.rb
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize ⇒ Adapter
constructor
A new instance of Adapter.
- #read(length = nil, outbuf = nil) ⇒ Object
- #write(chunk) ⇒ Object (also: #<<)
Constructor Details
#initialize ⇒ Adapter
Returns a new instance of Adapter.
6 7 8 9 10 11 |
# File 'lib/alipan/adapter.rb', line 6 def initialize() @producer = Fiber.new do yield self if block_given? nil end end |
Instance Method Details
#close ⇒ Object
29 30 |
# File 'lib/alipan/adapter.rb', line 29 def close end |
#closed? ⇒ Boolean
25 26 27 |
# File 'lib/alipan/adapter.rb', line 25 def closed? false end |
#read(length = nil, outbuf = nil) ⇒ Object
13 14 15 16 17 |
# File 'lib/alipan/adapter.rb', line 13 def read(length = nil, outbuf = nil) chunk = @producer.resume outbuf.replace(chunk) if outbuf && chunk chunk end |
#write(chunk) ⇒ Object Also known as: <<
19 20 21 |
# File 'lib/alipan/adapter.rb', line 19 def write(chunk) Fiber.yield chunk.to_s.force_encoding(Encoding::ASCII_8BIT) end |