Class: SidekiqIteration::NestedEnumerator

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_iteration/nested_enumerator.rb

Instance Method Summary collapse

Constructor Details

#initialize(enums, cursor: nil) ⇒ NestedEnumerator

Returns a new instance of NestedEnumerator.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sidekiq_iteration/nested_enumerator.rb', line 6

def initialize(enums, cursor: nil)
  unless enums.all?(Proc)
    raise ArgumentError, "enums must contain only procs/lambdas"
  end

  if cursor && enums.size != cursor.size
    raise ArgumentError, "cursor should have one item per enum"
  end

  @enums = enums
  @cursor = cursor || Array.new(enums.size)
end

Instance Method Details

#each(&block) ⇒ Object



19
20
21
22
23
# File 'lib/sidekiq_iteration/nested_enumerator.rb', line 19

def each(&block)
  return to_enum unless block_given?

  iterate([], [], 0, &block)
end