Class: Rake::RemoteTask
- Inherits:
-
Object
- Object
- Rake::RemoteTask
- Defined in:
- lib/vlad/enterprising.rb,
lib/vlad/translator.rb
Class Method Summary collapse
- .dialect(arg = { :set => {}}) ⇒ Object
-
.fetch(name, default = nil) ⇒ Object
Fetches environment variable
name
from the environment using defaultdefault
. - .host_env ⇒ Object
Instance Method Summary collapse
- #host_env ⇒ Object
-
#scp(local, remote) ⇒ Object
Use scp to send
local
toremote
on target_host.
Class Method Details
.dialect(arg = { :set => {}}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vlad/translator.rb', line 16 def self.dialect(arg={ :set => {}}) @@env["host_dialects"] ||= [] @@env["host_dialects"] << arg arg[:set].keys.each do |var| unless self.respond_to? var Object.send :define_method, var do Rake::RemoteTask.fetch var end end end end |
.fetch(name, default = nil) ⇒ Object
Fetches environment variable name
from the environment using default default
.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vlad/translator.rb', line 50 def self.fetch name, default = nil name = name.to_s if Symbol === name if @@env.has_key? name then protect_env(name) do v = @@env[name] v = @@env[name] = v.call if Proc === v v end elsif host_env.has_key? name.to_sym v = host_env[name.to_sym] if Proc === v v.call else v end elsif default v = @@env[name] = default else raise "can't fetch '#{name}'" raise Vlad::FetchError end end |
.host_env ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vlad/translator.rb', line 28 def self.host_env return {} unless Thread.current[:task] h = Thread.current[:task].target_host return {} unless h unless @@host_dialects[h] _cenv = {} @@env["host_dialects"].each do |env| begin env[:assert].call if env[:assert] && env[:assert].respond_to?(:call) _cenv.merge!(env[:set]) rescue end end @@host_dialects[h] = _cenv end @@host_dialects[h] end |
Instance Method Details
#host_env ⇒ Object
12 13 14 |
# File 'lib/vlad/translator.rb', line 12 def host_env self.class.host_env end |
#scp(local, remote) ⇒ Object
Use scp to send local
to remote
on target_host.
20 21 22 23 24 25 26 27 |
# File 'lib/vlad/enterprising.rb', line 20 def scp local, remote cmd = ["scp", "-rp", local, "#{@target_host}:#{remote}"].flatten.compact puts cmd.join(' ') success = system(*cmd) unless success then raise Vlad::CommandFailedError, "execution failed: #{cmd.join ' '}" end end |