capper 2.0.0.rc1 → 2.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/capper/base.rb +25 -0
- data/lib/capper/version.rb +1 -1
- metadata +1 -1
data/lib/capper/base.rb
CHANGED
@@ -120,6 +120,31 @@ ensure
|
|
120
120
|
ENV[name] = saved
|
121
121
|
end
|
122
122
|
|
123
|
+
# make sure a block and all commands within are only executed for servers
|
124
|
+
# matching the specified role even if ROLES or HOSTS is specified on the
|
125
|
+
# command line, in which case capistrano matches all servers by default. *sigh*
|
126
|
+
def ensure_role(role, &block)
|
127
|
+
if task = current_task
|
128
|
+
servers = find_servers_for_task(task)
|
129
|
+
else
|
130
|
+
servers = find_servers
|
131
|
+
end
|
132
|
+
|
133
|
+
servers = servers.select do |server|
|
134
|
+
self.roles[role.to_sym].include?(server)
|
135
|
+
end
|
136
|
+
|
137
|
+
return if servers.empty?
|
138
|
+
|
139
|
+
original, ENV['HOSTS'] = ENV['HOSTS'], servers.map { |s| s.host }.join(',')
|
140
|
+
|
141
|
+
begin
|
142
|
+
yield
|
143
|
+
ensure
|
144
|
+
ENV['HOSTS'] = original
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
123
148
|
# logs the command then executes it locally.
|
124
149
|
# returns the command output as a string
|
125
150
|
def run_locally(cmd)
|
data/lib/capper/version.rb
CHANGED