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