Module: HTTPX::Callbacks

Instance Method Summary collapse

Instance Method Details

#callbacks_for?(type) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#emit(type, *args) ⇒ Object



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

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