Module: HTTPX::Callbacks

Instance Method Summary collapse

Instance Method Details

#callbacks_for?(type) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/httpx/callbacks.rb', line 25

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

#emit(type, *args) ⇒ Object



21
22
23
# File 'lib/httpx/callbacks.rb', line 21

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
# File 'lib/httpx/callbacks.rb', line 5

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

#once(type, &block) ⇒ Object



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

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

#only(type, &block) ⇒ Object



16
17
18
19
# File 'lib/httpx/callbacks.rb', line 16

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