Sha256: 2217b82c8c50784da8085d2817939fbe27a382ee3c1c549085e6a614ca667487

Contents?: true

Size: 558 Bytes

Versions: 2

Compression:

Stored size: 558 Bytes

Contents

module Ruby
  module Reports
    module Services
      class EventsHandler
        PROGRESS_STEP = 10

        pattr_initialize :progress_callback, :error_callback do
          @error_callback ||= ->(e) { fail e }
        end

        def progress(progress, total, force = false)
          if progress_callback && (force || progress % PROGRESS_STEP == 0)
            progress_callback.call progress, total
          end
        end

        def error
          error_callback ? error_callback.call($ERROR_INFO) : fail
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-reports-0.1.0 lib/ruby/reports/services/events_handler.rb
ruby-reports-0.0.3 lib/ruby/reports/services/events_handler.rb