Module: TaliaUtil::Progressable

Included in:
TaliaCore::ActiveSource, TaliaCore::ActiveSourceParts::Xml::GenericReader
Defined in:
lib/talia_util/progressable.rb

Overview

Mix-in for a class that wishes to use decoupled progress meters.

Instance Method Summary collapse

Instance Method Details

#progressorObject

This is the object that will receive the progress messages



7
8
9
# File 'lib/talia_util/progressable.rb', line 7

def progressor
  @progressor
end

#progressor=(progr) ⇒ Object

Set the progressor class. The progress class should simply respond to a #run_with_progress(message, size, &block) class

Raises:

  • (ArgumentError)


13
14
15
16
# File 'lib/talia_util/progressable.rb', line 13

def progressor=(progr)
  raise(ArgumentError, "Illegal progressor") unless((progr == nil) || progr.respond_to?(:run_with_progress))
  @progressor = progr
end

#run_with_progress(message, size, progr = nil, &block) ⇒ Object

Runs some block with a progress meter. The containing block will be passed an object on which #inc can be called to increase the meter.

If no progressor object is passed in manually, the one configured in the class is used



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/talia_util/progressable.rb', line 23

def run_with_progress(message, size, progr = nil, &block)
  if(progr_object = (progr || progressor))
    progr_object.run_with_progress(message, size, &block)
  else
    dummy_prog = Object.new
    class << dummy_prog
      def inc
      end
    end
    block.call(dummy_prog)
  end
end