Class: Aliyun::OSS::Iterator::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/aliyun/oss/iterator.rb

Overview

Iterator base that stores fetched results and fetch more if needed.

Direct Known Subclasses

Buckets, Objects, Uploads

Instance Method Summary collapse

Constructor Details

#initialize(protocol, opts = {}) ⇒ Base

Returns a new instance of Base.



15
16
17
18
# File 'lib/aliyun/oss/iterator.rb', line 15

def initialize(protocol, opts = {})
  @protocol = protocol
  @results, @more = [], opts
end

Instance Method Details

#nextObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/aliyun/oss/iterator.rb', line 20

def next
  loop do
    # Communicate with the server to get more results
    fetch_more if @results.empty?

    # Return the first result
    r = @results.shift
    break unless r

    yield r
  end
end

#to_enumObject



33
34
35
# File 'lib/aliyun/oss/iterator.rb', line 33

def to_enum
  self.enum_for(:next)
end