Module: HTTPX::Callbacks
- Included in:
- Connection, HTTPX::Connection::HTTP1, HTTPX::Connection::HTTP2, Plugins::Callbacks::InstanceMethods, Plugins::CircuitBreaker::InstanceMethods, Plugins::Proxy::Socks4::SocksParser, Plugins::Proxy::Socks5::SocksParser, Request, Response
- Defined in:
- lib/httpx/callbacks.rb,
sig/callbacks.rbs
Instance Method Summary collapse
- #callbacks(type = nil) ⇒ Object
- #callbacks_for?(type) ⇒ Boolean
- #emit(type, *args) ⇒ void
- #on(type) {|arg0| ... } ⇒ ^(*untyped) -> void
- #once(type) {|arg0| ... } ⇒ ^(*untyped) -> void
Instance Method Details
#callbacks ⇒ Hash[Symbol, Array[_Callable]] #callbacks(arg0) ⇒ Array[_Callable]
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
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.
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
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
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 |