Sha256: 0ea36024db938a16ef8ea4c04f5db15f074d8bc5ef620174ade597ecfd91d4f2

Contents?: true

Size: 716 Bytes

Versions: 15

Compression:

Stored size: 716 Bytes

Contents

module Enumerable
  def with_progress(**args, &block)
    if block_given?
      progresser = progress(args)
      begin
        ret = each { |*o|
          res = yield(*o)
          progresser.tick
          res
        }
      rescue
        progresser.fail
        raise
      end
      progresser.complete
      ret
    else
      enum_for(:with_progress, args)
    end
  end

  private
  def progress(args)
    @progress ||= begin
      # Lazily read the size, for some enumerable this may be quite expensive and
      # using this method should come with a warning in the documentation.
      total = self.size unless args[:total]
      @progress = Progressrus.new({total: total}.merge(args))
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
progressrus-1.0.1 lib/progressrus/core_ext/enumerable.rb
progressrus-1.0.0 lib/progressrus/core_ext/enumerable.rb
progressrus-0.1.8 lib/progressrus/core_ext/enumerable.rb
progressrus-0.1.7 lib/progressrus/core_ext/enumerable.rb
progressrus-0.1.6 lib/progressrus/core_ext/enumerable.rb
progressrus-0.1.5 lib/progressrus/core_ext/enumerable.rb
progressrus-0.1.4 lib/progressrus/core_ext/enumerable.rb
progressrus-0.1.3 lib/progressrus/core_ext/enumerable.rb
progressrus-0.1.2 lib/progressrus/core_ext/enumerable.rb
progressrus-0.1.1 lib/progressrus/core_ext/enumerable.rb
progressrus-0.1.0 lib/progressrus/core_ext/enumerable.rb
progressrus-0.0.4 lib/progressrus/core_ext/enumerable.rb
progressrus-0.0.3 lib/progressrus/core_ext/enumerable.rb
progressrus-0.0.2 lib/progressrus/core_ext/enumerable.rb
progressrus-0.0.1 lib/progressrus/core_ext/enumerable.rb