Class: RCS::Deploy::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/rcs-common/deploy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Target

Returns a new instance of Target.



45
46
47
48
# File 'lib/rcs-common/deploy.rb', line 45

def initialize(params)
  @user = params[:user]
  @address = params[:address]
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



43
44
45
# File 'lib/rcs-common/deploy.rb', line 43

def address
  @address
end

#userObject (readonly)

Returns the value of attribute user.



43
44
45
# File 'lib/rcs-common/deploy.rb', line 43

def user
  @user
end

Instance Method Details

#add_slash(path) ⇒ Object



50
51
52
# File 'lib/rcs-common/deploy.rb', line 50

def add_slash(path)
  path.end_with?('/') ? "#{path}" : "#{path}/"
end

#mirror(local_folder, remote_folder, opts = {}) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rcs-common/deploy.rb', line 67

def mirror(local_folder, remote_folder, opts = {})
  opts[:trap] = true
  result = mirror!(local_folder, remote_folder, opts)
  changes = result.split("\n")[1..-3].reject { |x| x.empty? }
  changed = changes.size > 0 && changes != ["./"]

  if opts[:changes]
    changed ? result : nil
  else
    changed
  end
end

#mirror!(local_folder, remote_folder, opts = {}) ⇒ Object



60
61
62
63
64
65
# File 'lib/rcs-common/deploy.rb', line 60

def mirror!(local_folder, remote_folder, opts = {})
  src = add_slash(local_folder)
  dst = add_slash(remote_folder)

  run_without_ssh("rsync --delete -vazc \"#{src}\" #{user}@#{address}:\"#{dst}\"", opts)
end

#restart_service(name) ⇒ Object



80
81
82
# File 'lib/rcs-common/deploy.rb', line 80

def restart_service(name)
  run_with_ssh("net stop \"#{name}\"; net start \"#{name}\"")
end

#run_with_ssh(command, opts = {}) ⇒ Object Also known as: run



84
85
86
# File 'lib/rcs-common/deploy.rb', line 84

def run_with_ssh(command, opts = {})
  run_without_ssh("ssh #{user}@#{address} \""+ command.gsub('"', '\"') +"\"", opts)
end

#run_without_ssh(cmd, opts = {}) ⇒ Object



90
91
92
93
# File 'lib/rcs-common/deploy.rb', line 90

def run_without_ssh(cmd, opts = {})
  puts "executing: #{cmd}"
  opts[:trap] ? `#{cmd}` : Kernel.system(cmd)
end

#transfer(src, remote_folder, opts = {}) ⇒ Object



54
55
56
57
58
# File 'lib/rcs-common/deploy.rb', line 54

def transfer(src, remote_folder, opts = {})
  dst = add_slash(remote_folder)

  run_without_ssh("rsync -tcv #{src} #{user}@#{address}:\"#{dst}\"", opts)
end