Module: Foreplay::Engine::Port

Includes:
Foreplay
Included in:
Server
Defined in:
lib/foreplay/engine/port.rb

Constant Summary

Constants included from Foreplay

DEFAULT_PORT, PORT_GAP, VERSION

Instance Method Summary collapse

Methods included from Foreplay

#log, #terminate

Instance Method Details

#current_portObject



16
17
18
# File 'lib/foreplay/engine/port.rb', line 16

def current_port
  @current_port ||= port_details['current_port']
end

#current_port_fileObject



32
33
34
# File 'lib/foreplay/engine/port.rb', line 32

def current_port_file
  @current_port_file ||= ".foreplay/#{name}/current_port"
end

#current_port_remoteObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/foreplay/engine/port.rb', line 45

def current_port_remote
  return @current_port_remote if @current_port_remote

  @current_port_remote = Foreplay::Engine::Remote
                         .new(server, port_steps, instructions)
                         .__send__(mode)
                         .strip
                         .to_i

  if @current_port_remote == 0
    message = 'No instance is currently deployed'
    @current_port_remote = DEFAULT_PORT + PORT_GAP
  else
    message = "Current instance is using port #{@current_port_remote}"
  end

  log message, host: host
  @current_port_remote
end

#current_serviceObject



20
21
22
# File 'lib/foreplay/engine/port.rb', line 20

def current_service
  @current_service ||= port_details['current_service']
end

#former_portObject



24
25
26
# File 'lib/foreplay/engine/port.rb', line 24

def former_port
  @former_port ||= port_details['former_port']
end

#former_serviceObject



28
29
30
# File 'lib/foreplay/engine/port.rb', line 28

def former_service
  @former_service ||= port_details['former_service']
end

#hostObject



6
7
8
9
10
# File 'lib/foreplay/engine/port.rb', line 6

def host
  return @host if @host
  @host, _p = server.split(':') # Parse host + port
  @host
end

#nameObject



12
13
14
# File 'lib/foreplay/engine/port.rb', line 12

def name
  @name ||= instructions['name']
end

#port_detailsObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/foreplay/engine/port.rb', line 65

def port_details
  return @port_details if @port_details

  cp      = current_port_remote
  port    = instructions['port'].to_i
  ports   = [port + PORT_GAP, port]
  cp, fp  = cp == port ? ports : ports.reverse

  @port_details = {
    'current_port'    => cp,
    'current_service' => "#{name}-#{cp}",
    'former_port'     => fp,
    'former_service'  => "#{name}-#{fp}"
  }
end

#port_stepsObject



36
37
38
39
40
41
42
43
# File 'lib/foreplay/engine/port.rb', line 36

def port_steps
  @port_steps ||= [
    {
      'command' => "mkdir -p .foreplay/#{name} && touch #{current_port_file} && cat #{current_port_file}",
      'silent' => true
    }
  ]
end