Sha256: 517a06922c990bd88daf2103dd73f03d0f00bc1d384d35828b2e01f4a79495bb
Contents?: true
Size: 756 Bytes
Versions: 11
Compression:
Stored size: 756 Bytes
Contents
# frozen_string_literal: true module HTTPX module Callbacks def on(type, &action) callbacks(type) << action end def once(type, &block) on(type) do |*args, &callback| block.call(*args, &callback) :delete end end def only(type, &block) callbacks(type).clear on(type, &block) end def emit(type, *args) callbacks(type).delete_if { |pr| :delete == pr[*args] } # rubocop:disable Style/YodaCondition end protected def callbacks_for?(type) @callbacks.key?(type) && !@callbacks[type].empty? end def callbacks(type = nil) return @callbacks unless type @callbacks ||= Hash.new { |h, k| h[k] = [] } @callbacks[type] end end end
Version data entries
11 entries across 11 versions & 1 rubygems