Class: WebValve::Manager Private
- Inherits:
-
Object
- Object
- WebValve::Manager
- 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
- #allow_url(url) ⇒ Object private
- #allowing? ⇒ Boolean private
- #allowlisted_urls ⇒ Object private
- #clear! ⇒ Object private
- #enabled? ⇒ Boolean private
- #fake_service_configs ⇒ Object private
- #intercepting? ⇒ Boolean private
- #register(fake_service_class_name, **args) ⇒ Object private
- #reset! ⇒ Object private
- #setup ⇒ Object private
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.
65 66 67 |
# File 'lib/webvalve/manager.rb', line 65 def allowing? !in_always_intercepting_env? && explicitly_enabled? && services_enabled_by_default? end |
#allowlisted_urls ⇒ 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.
89 90 91 |
# File 'lib/webvalve/manager.rb', line 89 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.
76 77 78 79 80 81 |
# File 'lib/webvalve/manager.rb', line 76 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.
55 56 57 |
# File 'lib/webvalve/manager.rb', line 55 def enabled? in_always_intercepting_env? || explicitly_enabled? end |
#fake_service_configs ⇒ 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.
84 85 86 |
# File 'lib/webvalve/manager.rb', line 84 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.
60 61 62 |
# File 'lib/webvalve/manager.rb', line 60 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 |
#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.
70 71 72 73 |
# File 'lib/webvalve/manager.rb', line 70 def reset! clear! setup end |
#setup ⇒ 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.
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 52 |
# File 'lib/webvalve/manager.rb', line 25 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.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 |