Class: Capistrano::Former03::Rsync
- Inherits:
-
Object
- Object
- Capistrano::Former03::Rsync
- Defined in:
- lib/capistrano/former03/rsync.rb
Class Method Summary collapse
Instance Method Summary collapse
- #command ⇒ Object
- #dest_path ⇒ Object
-
#initialize(opts = {}) ⇒ Rsync
constructor
A new instance of Rsync.
- #password ⇒ Object
- #remote_options ⇒ Object
- #role ⇒ Object
- #src_path ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Rsync
Returns a new instance of Rsync.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/capistrano/former03/rsync.rb', line 19 def initialize(opts={}) # test for required flags required_flags = [:src_path, :dest_path] required_flags.each do |flag| if not opts.has_key?(flag) raise "Required arg '#{flag}' not given" end end if not opts[:src_type].nil? and not opts[:dest_type].nil? raise "Only one path can be remote" end # copy opts as instance vars opts.each do |k,v| instance_variable_set("@#{k}", v) end end |
Class Method Details
.build_path(path, type) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/capistrano/former03/rsync.rb', line 4 def self.build_path(path,type) return_path = "" if not type.nil? user = "#{type.user}@" unless type.user.nil? return_path += "#{user}#{type.hostname}:" end # Ensure path ends with slash return_path += path.to_s return_path << '/' unless return_path.end_with?('/') return_path end |
Instance Method Details
#command ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/capistrano/former03/rsync.rb', line 99 def command if @rsync_path.nil? = [:rsync] else = [@rsync_path] end # Add options += fetch(:rsync_options) # Add remote options if needed += # Add supplied options if not @rsync_options.nil? += @rsync_options end # Add source and destination += [src_path, dest_path] end |
#dest_path ⇒ Object
95 96 97 |
# File 'lib/capistrano/former03/rsync.rb', line 95 def dest_path return Rsync.build_path(@dest_path,@dest_type) end |
#password ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/capistrano/former03/rsync.rb', line 44 def password [role., fetch(:ssh_options)].each do |s| begin return s[:password] rescue next end end return nil end |
#remote_options ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/capistrano/former03/rsync.rb', line 56 def = [] = [] # No remote site return [] if role.nil? # Handle passsword if not password.nil? += [ :sshpass, '-p', "'#{password}'", :ssh, '-o', 'PubkeyAuthentication=no', ] end if not role.port.nil? += ['ssh'] if .length == 0 += ['-p', role.port] end # Add options += ['-e', "\"#{.join(' ')}\""] if .length > 0 # Add rsync path if needed rsync_path = role.properties.fetch(:deploy_rsync_path) if not rsync_path.nil? += ['--rsync-path', rsync_path] end return end |
#role ⇒ Object
39 40 41 |
# File 'lib/capistrano/former03/rsync.rb', line 39 def role @src_type || @dest_type end |
#src_path ⇒ Object
91 92 93 |
# File 'lib/capistrano/former03/rsync.rb', line 91 def src_path return Rsync.build_path(@src_path,@src_type) end |