Class: Pact::MockService::AppManager
- Inherits:
-
Object
- Object
- Pact::MockService::AppManager
- Includes:
- Logging, Singleton
- Defined in:
- lib/pact/mock_service/app_manager.rb
Instance Method Summary collapse
- #app_registered_on?(port) ⇒ Boolean
- #clear_all ⇒ Object
-
#initialize ⇒ AppManager
constructor
A new instance of AppManager.
- #kill_all ⇒ Object
- #register(app, host, port = nil) ⇒ Object
- #register_mock_service_for(name, url, options = {}) ⇒ Object
- #spawn_all ⇒ Object
- #urls_of_mock_services ⇒ Object
Constructor Details
#initialize ⇒ AppManager
Returns a new instance of AppManager.
16 17 18 19 |
# File 'lib/pact/mock_service/app_manager.rb', line 16 def initialize @apps_spawned = false @app_registrations = [] end |
Instance Method Details
#app_registered_on?(port) ⇒ Boolean
64 65 66 |
# File 'lib/pact/mock_service/app_manager.rb', line 64 def app_registered_on?(port) app_registrations.any? { |app_registration| app_registration.port == port } end |
#clear_all ⇒ Object
54 55 56 57 |
# File 'lib/pact/mock_service/app_manager.rb', line 54 def clear_all kill_all @app_registrations = [] end |
#kill_all ⇒ Object
49 50 51 52 |
# File 'lib/pact/mock_service/app_manager.rb', line 49 def kill_all app_registrations.find_all(&:spawned?).collect(&:kill) @apps_spawned = false end |
#register(app, host, port = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/pact/mock_service/app_manager.rb', line 35 def register(app, host, port = nil) if port existing = existing_app_on_host_and_port(host, port) raise "Port #{port} is already being used by #{existing}" if existing and not existing == app end app_registration = register_app(app, host, port) app_registration.spawn app_registration.port end |
#register_mock_service_for(name, url, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pact/mock_service/app_manager.rb', line 21 def register_mock_service_for(name, url, = {}) uri = URI(url) raise "Currently only http is supported" unless uri.scheme == 'http' uri.port = nil if [:find_available_port] app = Pact::MockService.new( name: name, log_file: create_log_file(name), pact_dir: pact_dir, pact_specification_version: .fetch(:pact_specification_version) ) register(app, uri.host, uri.port) end |
#spawn_all ⇒ Object
59 60 61 62 |
# File 'lib/pact/mock_service/app_manager.rb', line 59 def spawn_all app_registrations.find_all(&:not_spawned?).collect(&:spawn) @apps_spawned = true end |
#urls_of_mock_services ⇒ Object
45 46 47 |
# File 'lib/pact/mock_service/app_manager.rb', line 45 def urls_of_mock_services app_registrations.find_all(&:is_a_mock_service?).collect{ |ar| "http://#{ar.host}:#{ar.port}" } end |