Class: DeferredException::Enumerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/deferred_exception/enumerator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#defer_exceptions

Constructor Details

#initialize(enumerator) ⇒ Enumerator

Returns a new instance of Enumerator.



7
8
9
# File 'lib/deferred_exception/enumerator.rb', line 7

def initialize(enumerator)
  self.enumerator = enumerator
end

Instance Attribute Details

#enumeratorObject

Returns the value of attribute enumerator.



5
6
7
# File 'lib/deferred_exception/enumerator.rb', line 5

def enumerator
  @enumerator
end

Instance Method Details

#each(&block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/deferred_exception/enumerator.rb', line 11

def each(&block)
  enumerator.each do |item|
    begin
      block.call(item)
    rescue StandardError => e
      exceptions.push(e)
    end
  end

  unless exceptions.empty?
    raise DeferredException::ExceptionSet.new(exceptions)
  end

  enumerator
end

#exceptionsObject



27
28
29
# File 'lib/deferred_exception/enumerator.rb', line 27

def exceptions
  @exceptions ||= []
end