Class: Alipan::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/alipan/adapter.rb

Instance Method Summary collapse

Constructor Details

#initializeAdapter

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

#closeObject



29
30
# File 'lib/alipan/adapter.rb', line 29

def close
end

#closed?Boolean

Returns:

  • (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