Class: Pull::Values

Inherits:
Object
  • Object
show all
Defined in:
lib/pull/source/values.rb

Constant Summary collapse

DEFAULT_ABORT_PROC =
-> () {
  puts "abort abort"
}

Instance Method Summary collapse

Constructor Details

#initialize(array, on_abort = DEFAULT_ABORT_PROC) ⇒ Values

Returns a new instance of Values.



9
10
11
12
13
14
15
# File 'lib/pull/source/values.rb', line 9

def initialize(array, on_abort = DEFAULT_ABORT_PROC)
  array = objectify(array) unless array.kind_of?(Array)

  @array = array
  @index = 0
  @on_abort = on_abort
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pull/source/values.rb', line 17

def call
  -> (finish, callback) {
    if finish
      on_abort.()
      return nil
    end

    return false if !array[@index]

    callback.(array[@index])
    @index += 1
    return true
  }
end