Module: HTTPX::Callbacks

Instance Method Summary collapse

Instance Method Details

#callbacksHash[Symbol, Array[_Callable]] #callbacks(arg0) ⇒ Array[_Callable]

Overloads:

  • #callbacksHash[Symbol, Array[_Callable]]

    Returns:

  • #callbacks(arg0) ⇒ Array[_Callable]

    Parameters:

    • arg0 (Symbol)

    Returns:



28
29
30
31
32
33
# File 'lib/httpx/callbacks.rb', line 28

def callbacks(type = nil)
  return @callbacks unless type

  @callbacks ||= Hash.new { |h, k| h[k] = [] }
  @callbacks[type]
end

#callbacks_for?(type) ⇒ Boolean

Parameters:

  • (Symbol)

Returns:

  • (Boolean)


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

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

#emit(type, *args) ⇒ void

This method returns an undefined value.

Parameters:

  • (Symbol)
  • (Object)


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

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

#on(type) {|arg0| ... } ⇒ ^(*untyped) -> void

Parameters:

  • (Symbol)

Yields:

Yield Parameters:

  • arg0 (Object)

Yield Returns:

  • (void)

Returns:

  • (^(*untyped) -> void)


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

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

#once(type) {|arg0| ... } ⇒ ^(*untyped) -> void

Parameters:

  • (Symbol)

Yields:

Yield Parameters:

  • arg0 (Object)

Yield Returns:

  • (void)

Returns:

  • (^(*untyped) -> void)


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

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