module HTTPX::Callbacks

  1. lib/httpx/callbacks.rb

Methods

Public Instance

  1. callbacks_for?
  2. emit
  3. on
  4. once
  5. only

Protected Instance

  1. callbacks

Public Instance methods

callbacks_for?(type)
[show source]
   # File lib/httpx/callbacks.rb
27 def callbacks_for?(type)
28   @callbacks.key?(type) && @callbacks[type].any?
29 end
emit(type, *args)
[show source]
   # File lib/httpx/callbacks.rb
23 def emit(type, *args)
24   callbacks(type).delete_if { |pr| :delete == pr.call(*args) } # rubocop:disable Style/YodaCondition
25 end
on(type, &action)
[show source]
  # File lib/httpx/callbacks.rb
5 def on(type, &action)
6   callbacks(type) << action
7   self
8 end
once(type, &block)
[show source]
   # File lib/httpx/callbacks.rb
10 def once(type, &block)
11   on(type) do |*args, &callback|
12     block.call(*args, &callback)
13     :delete
14   end
15   self
16 end
only(type, &block)
[show source]
   # File lib/httpx/callbacks.rb
18 def only(type, &block)
19   callbacks(type).clear
20   on(type, &block)
21 end

Protected Instance methods

callbacks(type = nil)
[show source]
   # File lib/httpx/callbacks.rb
33 def callbacks(type = nil)
34   return @callbacks unless type
35 
36   @callbacks ||= Hash.new { |h, k| h[k] = [] }
37   @callbacks[type]
38 end