class Dockerspec::Engine::Specinfra::Backend
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.
Public Class Methods
The Specinfra
backend constructor.
@param backend [Symbol, Specinfra::Backend::Base, Class] The backend
can be the backend name as a symbol, a Specinfra backend object or a Specinfra backend class.
@api public
# File lib/dockerspec/engine/specinfra/backend.rb, line 45 def initialize(backend) @backend = backend end
Public Instance Methods
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.
@return [Mixed] The value of the attribute to read.
@api public
# File lib/dockerspec/engine/specinfra/backend.rb, line 117 def backend_instance_attribute(name) backend_instance.instance_variable_get("@#{name}".to_sym) end
Resets the Specinfra
backend.
@return void
@api public
# File lib/dockerspec/engine/specinfra/backend.rb, line 103 def reset backend_class.instance_set(nil) end
Restores the Specinfra
backend instance.
@return void
@api public
# 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
Restores the testing context for a container.
Used with Docker Compose to choose the container to test.
@param container_name [String, Symbol] The name of the container.
@return void
@api public
# 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
Saves the Specinfra
backend instance reference internally.
@return void
@api public
# File lib/dockerspec/engine/specinfra/backend.rb, line 56 def save @saved_backend_name = ::Specinfra.configuration.backend @saved_backend_instance = backend_instance end
Protected Instance Methods
Returns the current Specinfra
backend class.
@return [Class] The Specinfra
backend class.
@api private
# File lib/dockerspec/engine/specinfra/backend.rb, line 141 def backend_class @backend_class ||= begin return @backend.class if @backend.is_a?(::Specinfra::Backend::Base) ::Specinfra::Backend.const_get(@backend.to_s.to_camel_case) end end