Class: Foreplay::Engine::Server

Inherits:
Object
  • Object
show all
Includes:
Port
Defined in:
lib/foreplay/engine/server.rb

Constant Summary

Constants included from Foreplay

DEFAULT_PORT, PORT_GAP, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Port

#current_port, #current_port_file, #current_port_remote, #current_service, #former_port, #former_service, #host, #name, #port_details, #port_steps

Methods included from Foreplay

#log, #terminate

Constructor Details

#initialize(e, m, i, s) ⇒ Server



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/foreplay/engine/server.rb', line 7

def initialize(e, m, i, s)
  @environment  = e
  @mode         = m
  @instructions = i
  @server       = s

  @path = nil
  @host = nil
  @port_details = nil
  @current_port_remote = nil
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



5
6
7
# File 'lib/foreplay/engine/server.rb', line 5

def environment
  @environment
end

#instructionsObject (readonly)

Returns the value of attribute instructions.



5
6
7
# File 'lib/foreplay/engine/server.rb', line 5

def instructions
  @instructions
end

#modeObject (readonly)

Returns the value of attribute mode.



5
6
7
# File 'lib/foreplay/engine/server.rb', line 5

def mode
  @mode
end

#serverObject (readonly)

Returns the value of attribute server.



5
6
7
# File 'lib/foreplay/engine/server.rb', line 5

def server
  @server
end

Instance Method Details

#envObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/foreplay/engine/server.rb', line 44

def env
  instructions['env'] = {} unless instructions.key? 'env'

  instructions['env'].merge!(
    'HOME'      => '$HOME',
    'SHELL'     => '$SHELL',
    'PATH'      => '$PATH:`which bundle`',
    'GEM_HOME'  => '$HOME/.rvm/gems/`rvm tools identifier`',
    'RAILS_ENV' => environment
  )
end

#executeObject



19
20
21
22
23
24
25
# File 'lib/foreplay/engine/server.rb', line 19

def execute
  execute_announce
  foreman
  env

  Foreplay::Engine::Remote.new(server, steps, instructions).__send__ mode
end

#execute_announceObject



27
28
29
30
31
# File 'lib/foreplay/engine/server.rb', line 27

def execute_announce
  preposition = mode == :deploy ? 'to' : 'for'
  puts "#{mode.capitalize}ing #{name.yellow} #{preposition} #{host.yellow} "\
      "for the #{role.dup.yellow} role in the #{environment.dup.yellow} environment"
end

#foremanObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/foreplay/engine/server.rb', line 33

def foreman
  instructions['foreman'] = {} unless instructions.key? 'foreman'

  instructions['foreman'].merge!(
    'app'   => current_service,
    'port'  => current_port,
    'user'  => user,
    'log'   => "$HOME/#{path}/#{current_port}/log"
  )
end

#pathObject



64
65
66
67
68
69
70
71
# File 'lib/foreplay/engine/server.rb', line 64

def path
  return @path if @path

  @path = instructions['path']
  @path.gsub! '%u', user
  @path.gsub! '%a', name
  @path
end

#roleObject



56
57
58
# File 'lib/foreplay/engine/server.rb', line 56

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

#stepsObject



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/foreplay/engine/server.rb', line 73

def steps
  concurrency = foreman.key?('concurrency') ? " -m #{foreman['concurrency']}" : ''

  @steps ||= YAML.load(
    ERB.new(
      File.read(
        "#{File.dirname(__FILE__)}/steps.yml"
      )
    ).result(binding)
  )
end

#userObject



60
61
62
# File 'lib/foreplay/engine/server.rb', line 60

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