Class: Enumerable::Progress

Inherits:
Object show all
Defined in:
lib/vex/base/enumerable/progress.rb,
lib/vex/base/enumerable/progress.rb

Direct Known Subclasses

ConsoleProgress

Constant Summary collapse

IMPLEMENTATIONS =
{
  :console => ConsoleProgress
}

Instance Method Summary collapse

Constructor Details

#initialize(base, count = nil) ⇒ Progress

Returns a new instance of Progress.



3
4
5
6
7
8
# File 'lib/vex/base/enumerable/progress.rb', line 3

def initialize(base, count=nil)
  @base = base
  @idx = 0
  @count = count
  @count ||= base.is_a?(Range) ? (base.max - base.min + 1) : length
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/vex/base/enumerable/progress.rb', line 10

def method_missing(sym, *args)
  return @base.send(sym, *args) unless block_given?

  r = @base.send sym, *args do |*args|
    begin
      yield *args
    ensure
      @idx += 1
      on_progress(@idx, @count)
    end
  end
end