Class: Derelict::Connection

Inherits:
Object
  • Object
show all
Includes:
Utils::Logger
Defined in:
lib/derelict/connection.rb,
lib/derelict/connection/invalid.rb,
lib/derelict/connection/not_found.rb

Overview

Connects a Derelict::Instance to its use in a particular directory

Defined Under Namespace

Classes: Invalid, NotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Logger

#logger

Constructor Details

#initialize(instance, path) ⇒ Connection

Initializes a Connection for use in a particular directory

* instance: The Derelict::Instance to use to control Vagrant
* path:     The project path, which contains the Vagrantfile


17
18
19
20
21
# File 'lib/derelict/connection.rb', line 17

def initialize(instance, path)
  @instance = instance
  @path = path
  logger.debug "Successfully initialized #{description}"
end

Instance Attribute Details

#instanceObject (readonly)

Returns the value of attribute instance.



10
11
12
# File 'lib/derelict/connection.rb', line 10

def instance
  @instance
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/derelict/connection.rb', line 11

def path
  @path
end

Instance Method Details

#descriptionObject

Provides a description of this Connection

Mainly used for log messages.



72
73
74
# File 'lib/derelict/connection.rb', line 72

def description
  "Derelict::Connection at '#{path}' using #{instance.description}"
end

#execute(subcommand, *arguments, &block) ⇒ Object

Executes a Vagrant subcommand using this connection

* subcommand: Vagrant subcommand to run (:up, :status, etc.)
* arguments:  Arguments to pass to the subcommand (optional)
* block:      Passed through to @instance#execute


40
41
42
43
44
45
# File 'lib/derelict/connection.rb', line 40

def execute(subcommand, *arguments, &block)
  log_execute subcommand, *arguments
  Dir.chdir path do
    instance.execute subcommand.to_sym, *arguments, &block
  end
end

#execute!(subcommand, *arguments, &block) ⇒ Object

Executes a Vagrant subcommand, raising an exception on failure

* subcommand: Vagrant subcommand to run (:up, :status, etc.)
* arguments:  Arguments to pass to the subcommand (optional)
* block:      Passed through to Derelict::Executer.execute

Raises Derelict::Instance::CommandFailed if the command fails.



54
55
56
57
58
59
# File 'lib/derelict/connection.rb', line 54

def execute!(subcommand, *arguments, &block)
  log_execute subcommand, *arguments
  Dir.chdir path do
    instance.execute! subcommand.to_sym, *arguments, &block
  end
end

#validate!Object

Validates the data used for this connection

Raises exceptions on failure:

* +Derelict::Connection::NotFound+ if the path is not found


28
29
30
31
32
33
# File 'lib/derelict/connection.rb', line 28

def validate!
  logger.debug "Starting validation for #{description}"
  raise NotFound.new path unless File.exists? path
  logger.info "Successfully validated #{description}"
  self
end

#vm(name) ⇒ Object

Retrieves a Derelict::VirtualMachine for a particular VM

* name: The name of the virtual machine to retrieve


64
65
66
67
# File 'lib/derelict/connection.rb', line 64

def vm(name)
  logger.debug "Retrieving VM '#{name}' from #{description}"
  Derelict::VirtualMachine.new(self, name).validate!
end