Class: Pact::Consumer::AppManager
- Inherits:
-
Object
- Object
- Pact::Consumer::AppManager
- Includes:
- Logging, Singleton
- Defined in:
- lib/pact/consumer/app_manager.rb
Instance Method Summary collapse
- #app_registered_on?(port) ⇒ Boolean
- #clear_all ⇒ Object
- #existing_app_on_port(port) ⇒ Object
-
#initialize ⇒ AppManager
constructor
A new instance of AppManager.
- #kill_all ⇒ Object
- #ports_of_mock_services ⇒ Object
- #register(app, port = FindAPort.available_port) ⇒ Object
- #register_mock_service_for(name, url) ⇒ Object
- #spawn_all ⇒ Object
Methods included from Logging
Constructor Details
#initialize ⇒ AppManager
Returns a new instance of AppManager.
18 19 20 21 |
# File 'lib/pact/consumer/app_manager.rb', line 18 def initialize @apps_spawned = false @app_registrations = [] end |
Instance Method Details
#app_registered_on?(port) ⇒ Boolean
44 45 46 |
# File 'lib/pact/consumer/app_manager.rb', line 44 def app_registered_on?(port) app_registrations.any? { |app_registration| app_registration.port == port } end |
#clear_all ⇒ Object
57 58 59 60 |
# File 'lib/pact/consumer/app_manager.rb', line 57 def clear_all kill_all @app_registrations = [] end |
#existing_app_on_port(port) ⇒ Object
39 40 41 42 |
# File 'lib/pact/consumer/app_manager.rb', line 39 def existing_app_on_port port app_registration = @app_registrations.find { |app_registration| app_registration.port == port } app_registration ? app_registration.app : nil end |
#kill_all ⇒ Object
52 53 54 55 |
# File 'lib/pact/consumer/app_manager.rb', line 52 def kill_all app_registrations.find_all(&:spawned?).collect(&:kill) @apps_spawned = false end |
#ports_of_mock_services ⇒ Object
48 49 50 |
# File 'lib/pact/consumer/app_manager.rb', line 48 def ports_of_mock_services app_registrations.find_all(&:is_a_mock_service?).collect(&:port) end |
#register(app, port = FindAPort.available_port) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/pact/consumer/app_manager.rb', line 31 def register(app, port = FindAPort.available_port) existing = existing_app_on_port port raise "Port #{port} is already being used by #{existing}" if existing and not existing == app app_registration = register_app app, port app_registration.spawn if @apps_spawned port end |
#register_mock_service_for(name, url) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/pact/consumer/app_manager.rb', line 23 def register_mock_service_for name, url uri = URI(url) raise "Currently only http is supported" unless uri.scheme == 'http' raise "Currently only services on localhost are supported" unless uri.host == 'localhost' register(MockService.new(log_file: create_log_file(name), name: name), uri.port) end |
#spawn_all ⇒ Object
62 63 64 65 |
# File 'lib/pact/consumer/app_manager.rb', line 62 def spawn_all app_registrations.find_all(&:not_spawned?).collect(&:spawn) @apps_spawned = true end |