Top Level Namespace
Defined Under Namespace
Instance Method Summary collapse
-
#host(host_name, *roles) ⇒ Object
Declare a remote host and its roles.
-
#now ⇒ Object
used by update, out here so we can ensure all threads have the same value.
-
#put(remote_path, base_name = 'vlad.unknown') ⇒ Object
Copy a (usually generated) file to
remote_path
. -
#remote_task(name, *args_options, &b) ⇒ Object
Declare a Vlad task that will execute on all hosts by default.
-
#role(role_name, host = nil, args = {}) ⇒ Object
Declare a role and assign a remote host to it.
-
#rsync(local, remote) ⇒ Object
rsync the given files to
target_host
. -
#run(*args, &b) ⇒ Object
Execute the given command on the
target_host
for the current task. -
#set(name, val = nil, &b) ⇒ Object
Declare a variable called
name
and assign it a value. -
#target_host ⇒ Object
Returns the name of the host that the current task is executing on.
Instance Method Details
#host(host_name, *roles) ⇒ Object
Declare a remote host and its roles. Equivalent to role
, but shorter for multiple roles.
12 13 14 |
# File 'lib/rake_remote_task.rb', line 12 def host host_name, *roles Rake::RemoteTask.host host_name, *roles end |
#now ⇒ Object
used by update, out here so we can ensure all threads have the same value
5 6 7 |
# File 'lib/vlad/core.rb', line 5 def now @now ||= Time.now.utc.strftime("%Y%m%d%H%M.%S") end |
#put(remote_path, base_name = 'vlad.unknown') ⇒ Object
Copy a (usually generated) file to remote_path
. Contents of block are copied to remote_path
and you may specify an optional base_name for the tempfile (aids in debugging).
21 22 23 24 25 26 27 |
# File 'lib/rake_remote_task.rb', line 21 def put remote_path, base_name = 'vlad.unknown' Tempfile.open base_name do |fp| fp.puts yield fp.flush rsync fp.path, remote_path end end |
#remote_task(name, *args_options, &b) ⇒ Object
Declare a Vlad task that will execute on all hosts by default. To limit that task to specific roles, use:
remote_task :example, :arg1, :roles => [:app, :web] do
34 35 36 |
# File 'lib/rake_remote_task.rb', line 34 def remote_task name, *, &b Rake::RemoteTask.remote_task name, *, &b end |
#role(role_name, host = nil, args = {}) ⇒ Object
Declare a role and assign a remote host to it. Equivalent to the host
method; provided for capistrano compatibility.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rake_remote_task.rb', line 41 def role role_name, host = nil, args = {} if block_given? then raise ArgumentError, 'host not allowed with block' unless host.nil? begin Rake::RemoteTask.current_roles << role_name yield ensure Rake::RemoteTask.current_roles.delete role_name end else raise ArgumentError, 'host required' if host.nil? Rake::RemoteTask.role role_name, host, args end end |
#rsync(local, remote) ⇒ Object
rsync the given files to target_host
.
65 66 67 |
# File 'lib/rake_remote_task.rb', line 65 def rsync local, remote Thread.current[:task].rsync local, remote end |
#run(*args, &b) ⇒ Object
Execute the given command on the target_host
for the current task.
60 61 62 |
# File 'lib/rake_remote_task.rb', line 60 def run *args, &b Thread.current[:task].run(*args, &b) end |
#set(name, val = nil, &b) ⇒ Object
Declare a variable called name
and assign it a value. A globally-visible method with the name of the variable is defined. If a block is given, it will be called when the variable is first accessed. Subsequent references to the variable will always return the same value. Raises ArgumentError
if the name
would conflict with an existing method.
75 76 77 |
# File 'lib/rake_remote_task.rb', line 75 def set name, val = nil, &b Rake::RemoteTask.set name, val, &b end |
#target_host ⇒ Object
Returns the name of the host that the current task is executing on. target_host
can uniquely identify a particular task/host combination.
82 83 84 |
# File 'lib/rake_remote_task.rb', line 82 def target_host Thread.current[:task].target_host end |