lib/httpx/callbacks.rb in httpx-0.13.2 vs lib/httpx/callbacks.rb in httpx-0.14.0

- old
+ new

@@ -4,21 +4,30 @@ module Callbacks def on(type, &action) callbacks(type) << action end - def once(event, &block) - on(event) do |*args, &callback| + 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| pr[*args] == :delete } + 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] = [] }