Sha256: 1dfc8d25c3bb00ee52c2935e2c179fbb977050e4505459e978406c1e6a51ea64
Contents?: true
Size: 1.12 KB
Versions: 27
Compression:
Stored size: 1.12 KB
Contents
module TaliaUtil # Mix-in for a class that wishes to use decoupled progress meters. module Progressable # This is the object that will receive the progress messages def progressor @progressor end # Set the progressor class. The progress class should simply respond to # a #run_with_progress(message, size, &block) class def progressor=(progr) raise(ArgumentError, "Illegal progressor") unless((progr == nil) || progr.respond_to?(:run_with_progress)) @progressor = progr end # 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 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 end end
Version data entries
27 entries across 27 versions & 1 rubygems