Class: WebValve::Manager Private

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/webvalve/manager.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#allow_url(url) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
23
# File 'lib/webvalve/manager.rb', line 20

def allow_url(url)
  raise "#{url} already registered" if allowlisted_urls.include?(url)
  allowlisted_urls << url
end

#allowing?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


64
65
66
# File 'lib/webvalve/manager.rb', line 64

def allowing?
  !in_always_intercepting_env? && explicitly_enabled? && services_enabled_by_default?
end

#allowlisted_urlsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



82
83
84
# File 'lib/webvalve/manager.rb', line 82

def allowlisted_urls
  @allowlisted_urls ||= Set.new
end

#enabled?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


54
55
56
# File 'lib/webvalve/manager.rb', line 54

def enabled?
  in_always_intercepting_env? || explicitly_enabled?
end

#fake_service_configsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



77
78
79
# File 'lib/webvalve/manager.rb', line 77

def fake_service_configs
  @fake_service_configs ||= []
end

#intercepting?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


59
60
61
# File 'lib/webvalve/manager.rb', line 59

def intercepting?
  in_always_intercepting_env? || (explicitly_enabled? && !services_enabled_by_default?)
end

#register(fake_service_class_name, **args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
17
18
# File 'lib/webvalve/manager.rb', line 14

def register(fake_service_class_name, **args)
  raise "register must be called with a string to comply with Rails autoloading" unless fake_service_class_name.is_a?(String)
  raise "#{fake_service_class_name.inspect} already registered" if fake_service_configs.any? { |c| c.service_class_name == fake_service_class_name }
  fake_service_configs << FakeServiceConfig.new(service_class_name: fake_service_class_name, **args)
end

#resetObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



69
70
71
72
73
74
# File 'lib/webvalve/manager.rb', line 69

def reset
  allowlisted_urls.clear
  fake_service_configs.clear
  stubbed_urls.clear
  WebMock.reset!
end

#setupObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/webvalve/manager.rb', line 25

def setup
  return unless enabled?

  if intercepting?
    fake_service_configs.each do |config|
      if !WebValve.env.test? && config.explicitly_enabled?
        allowlist_service config
      else
        webmock_service config
      end
    end
    WebMock.disable_net_connect! webmock_disable_options
    WebMock.enable!
  end

  if allowing?
    fake_service_configs.each do |config|
      if config.explicitly_disabled?
        webmock_service config
      end
    end
    if fake_service_configs.any?(&:explicitly_disabled?)
      WebMock.allow_net_connect!
      WebMock.enable!
    end
  end
end