Module: HTTPX::Callbacks

Instance Method Summary collapse

Instance Method Details

#callbacks_for?(type) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/httpx/callbacks.rb', line 27

def callbacks_for?(type)
  @callbacks.key?(type) && @callbacks[type].any?
end

#emit(type, *args) ⇒ Object



23
24
25
# File 'lib/httpx/callbacks.rb', line 23

def emit(type, *args)
  callbacks(type).delete_if { |pr| :delete == pr.call(*args) } # rubocop:disable Style/YodaCondition
end

#on(type, &action) ⇒ Object



5
6
7
8
# File 'lib/httpx/callbacks.rb', line 5

def on(type, &action)
  callbacks(type) << action
  self
end

#once(type, &block) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/httpx/callbacks.rb', line 10

def once(type, &block)
  on(type) do |*args, &callback|
    block.call(*args, &callback)
    :delete
  end
  self
end

#only(type, &block) ⇒ Object



18
19
20
21
# File 'lib/httpx/callbacks.rb', line 18

def only(type, &block)
  callbacks(type).clear
  on(type, &block)
end