Class: Dockerspec::Engine::Specinfra::Backend
- Inherits:
-
Object
- Object
- Dockerspec::Engine::Specinfra::Backend
- Defined in:
- lib/dockerspec/engine/specinfra/backend.rb
Overview
A class to handle the underlying Specinfra backend.
This class saves Specinfra instance in internally and then it is able to recover it from there and setup the running environment accordingly.
This class uses a small hack in the Specinfra class to reset its internal singleton instance.
Instance Method Summary collapse
-
#backend_instance_attribute(name) ⇒ Mixed
Gets the internal attribute value from the Specinfra backend object.
-
#initialize(backend) ⇒ Backend
constructor
The Specinfra backend constructor.
-
#reset ⇒ Object
Resets the Specinfra backend.
-
#restore ⇒ Object
Restores the Specinfra backend instance.
-
#restore_container(container_name) ⇒ Object
Restores the testing context for a container.
-
#save ⇒ Object
Saves the Specinfra backend instance reference internally.
Constructor Details
#initialize(backend) ⇒ Backend
The Specinfra backend constructor.
45 46 47 |
# File 'lib/dockerspec/engine/specinfra/backend.rb', line 45 def initialize(backend) @backend = backend end |
Instance Method Details
#backend_instance_attribute(name) ⇒ Mixed
Gets the internal attribute value from the Specinfra backend object.
Used mainly to get information from the running containers like their name or their IP address.
117 118 119 |
# File 'lib/dockerspec/engine/specinfra/backend.rb', line 117 def backend_instance_attribute(name) backend_instance.instance_variable_get("@#{name}".to_sym) end |
#reset ⇒ Object
Resets the Specinfra backend.
103 104 105 |
# File 'lib/dockerspec/engine/specinfra/backend.rb', line 103 def reset backend_class.instance_set(nil) end |
#restore ⇒ Object
Restores the Specinfra backend instance.
68 69 70 71 72 73 74 |
# File 'lib/dockerspec/engine/specinfra/backend.rb', line 68 def restore backend_class.instance_set(@saved_backend_instance) if ::Specinfra.configuration.backend != @saved_backend_name backend_class.host_reset ::Specinfra.configuration.backend = @saved_backend_name end end |
#restore_container(container_name) ⇒ Object
Restores the testing context for a container.
Used with Docker Compose to choose the container to test.
87 88 89 90 91 92 93 94 |
# File 'lib/dockerspec/engine/specinfra/backend.rb', line 87 def restore_container(container_name) current_container_name = ::Specinfra.configuration.docker_compose_container return if current_container_name == container_name ::Specinfra.configuration.docker_compose_container(container_name) # TODO: Save the host family instead of always reseting it: backend_class.host_reset end |
#save ⇒ Object
Saves the Specinfra backend instance reference internally.
56 57 58 59 |
# File 'lib/dockerspec/engine/specinfra/backend.rb', line 56 def save @saved_backend_name = ::Specinfra.configuration.backend @saved_backend_instance = backend_instance end |