Module: Minestrone::Configuration::Connections

Included in:
Minestrone::Configuration
Defined in:
lib/minestrone/configuration/connections.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



9
10
11
# File 'lib/minestrone/configuration/connections.rb', line 9

def session
  @session
end

Instance Method Details

#connect!Object

Used to force a connection to be made to the current task’s server. Connections are normally made lazily in Minestrone–you can use this to force them open before performing some operation that might be time-sensitive.



21
22
23
# File 'lib/minestrone/configuration/connections.rb', line 21

def connect!
  establish_connection_to_server
end

#establish_connection_to_serverObject

Ensures that there is an active session for the server.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/minestrone/configuration/connections.rb', line 27

def establish_connection_to_server
  return if @session

  server = resolved_server
  @session = SSH.connect(server, self)
rescue Exception => err
  raise err unless server

  error = ConnectionError.new("connection failed for: #{server} (#{err.class}: #{err.message})")
  error.host = server
  raise error
end

#execute_on_serverObject

Determines the configured server, establishes a connection to it, and yields to the command and transfer layers.

Raises:

  • (ArgumentError)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/minestrone/configuration/connections.rb', line 43

def execute_on_server
  raise ArgumentError, "expected a block" unless block_given?

  task = current_task
  return if task && task.continue_on_error? && @failed

  begin
    establish_connection_to_server
  rescue ConnectionError => error
    raise error unless task && task.continue_on_error?
    @failed = true
    return
  end

  begin
    yield
  rescue RemoteError => error
    raise error unless task && task.continue_on_error?
    @failed = true
  end
end

#initialize_connectionsObject

:nodoc:



11
12
13
14
# File 'lib/minestrone/configuration/connections.rb', line 11

def initialize_connections #:nodoc:
  @session = nil
  @failed = false
end