Class: Botz::Looper

Inherits:
Object
  • Object
show all
Defined in:
lib/botz/looper.rb

Overview

looper

Instance Method Summary collapse

Constructor Details

#initialize(resource, binder, loop_block) ⇒ Looper

Returns a new instance of Looper.



7
8
9
10
11
# File 'lib/botz/looper.rb', line 7

def initialize(resource, binder, loop_block)
  @resource = resource
  @binder = binder
  @loop_block = loop_block
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
# File 'lib/botz/looper.rb', line 13

def call
  yielder = lambda do |element|
    result = @binder.new(element).result
    fail "#{element}\n\n#{result.errors.full_messages}" if result.invalid?

    yield result
  end
  @loop_block.call(@resource, yielder)
end