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.



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

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)


66
67
68
# File 'lib/webvalve/manager.rb', line 66

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.



90
91
92
# File 'lib/webvalve/manager.rb', line 90

def allowlisted_urls
  @allowlisted_urls ||= Set.new
end

#clear!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.



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

def clear!
  allowlisted_urls.clear
  fake_service_configs.clear
  stubbed_urls.clear
  WebMock.reset!
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)


56
57
58
# File 'lib/webvalve/manager.rb', line 56

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.



85
86
87
# File 'lib/webvalve/manager.rb', line 85

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)


61
62
63
# File 'lib/webvalve/manager.rb', line 61

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.



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

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

#reset!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.



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

def reset!
  clear!
  setup
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.



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
52
53
# File 'lib/webvalve/manager.rb', line 26

def setup
  return unless enabled?
  load_configs!

  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