Class: JobIteration::EnumeratorBuilder::Wrapper

Inherits:
Enumerator
  • Object
show all
Defined in:
lib/job-iteration/enumerator_builder.rb

Overview

These wrappers ensure we have a custom type that we can assert on in Iteration. It's useful that the wrapper passed to EnumeratorBuilder in enumerator_builder is always the type that is returned from build_enumerator. This prevents people from implementing custom Enumerators without wrapping them in enumerator_builder.wrap(custom_enum). We don't do this yet for backwards compatibility with raw calls to EnumeratorBuilder. Think of these wrappers the way you should a middleware.

Class Method Summary collapse

Class Method Details

.wrap(_builder, enum) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/job-iteration/enumerator_builder.rb', line 24

def wrap(_builder, enum)
  new(-> { enum.size }) do |yielder|
    enum.each do |*val|
      yielder.yield(*val)
    end
  end
end