Class: Foreplay::Engine::Server
- Inherits:
-
Object
- Object
- Foreplay::Engine::Server
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
#environment ⇒ Object
Returns the value of attribute environment.
5
6
7
|
# File 'lib/foreplay/engine/server.rb', line 5
def environment
@environment
end
|
#instructions ⇒ Object
Returns the value of attribute instructions.
5
6
7
|
# File 'lib/foreplay/engine/server.rb', line 5
def instructions
@instructions
end
|
#mode ⇒ Object
Returns the value of attribute mode.
5
6
7
|
# File 'lib/foreplay/engine/server.rb', line 5
def mode
@mode
end
|
#server ⇒ Object
Returns the value of attribute server.
5
6
7
|
# File 'lib/foreplay/engine/server.rb', line 5
def server
@server
end
|
Instance Method Details
#env ⇒ Object
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
|
#execute ⇒ Object
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_announce ⇒ Object
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
|
#foreman ⇒ Object
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
|
#path ⇒ Object
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
|
#role ⇒ Object
56
57
58
|
# File 'lib/foreplay/engine/server.rb', line 56
def role
@role ||= instructions['role']
end
|
#steps ⇒ Object
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
|
#user ⇒ Object
60
61
62
|
# File 'lib/foreplay/engine/server.rb', line 60
def user
@user ||= instructions['user']
end
|