Class: WebMock::CallbackRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/webmock/callback_registry.rb

Constant Summary collapse

@@callbacks =
[]

Class Method Summary collapse

Class Method Details

.add_callback(options, block) ⇒ Object



5
6
7
# File 'lib/webmock/callback_registry.rb', line 5

def self.add_callback(options, block)
  @@callbacks << {options: options, block: block}
end

.any_callbacks?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/webmock/callback_registry.rb', line 30

def self.any_callbacks?
  !@@callbacks.empty?
end

.callbacksObject



9
10
11
# File 'lib/webmock/callback_registry.rb', line 9

def self.callbacks
  @@callbacks
end

.invoke_callbacks(options, request_signature, response) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/webmock/callback_registry.rb', line 13

def self.invoke_callbacks(options, request_signature, response)
  return if @@callbacks.empty?
  CallbackRegistry.callbacks.each do |callback|
    except = callback[:options][:except]
    real_only = callback[:options][:real_requests_only]
    unless except && except.include?(options[:lib])
      if !real_only || options[:real_request]
        callback[:block].call(request_signature, response)
      end
    end
  end
end

.resetObject



26
27
28
# File 'lib/webmock/callback_registry.rb', line 26

def self.reset
  @@callbacks = []
end