Class: RakeDeploy::Rsyncer

Inherits:
Object
  • Object
show all
Defined in:
lib/rake_deploy.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ Rsyncer

Returns a new instance of Rsyncer.



41
42
43
44
# File 'lib/rake_deploy.rb', line 41

def initialize(name, options)
  @name = name
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



39
40
41
# File 'lib/rake_deploy.rb', line 39

def name
  @name
end

Class Method Details

.option_accessor(name) ⇒ Object



50
51
52
53
54
# File 'lib/rake_deploy.rb', line 50

def self.option_accessor(name)
  define_method name do
    indifferent_hash_access(name) || missing_option(name)
  end
end

Instance Method Details

#exitstatusObject



84
85
86
# File 'lib/rake_deploy.rb', line 84

def exitstatus
  @wait_thr.value.exitstatus == 0 ? 'succeeded' : 'failed'
end

#indifferent_hash_access(name) ⇒ Object



46
47
48
# File 'lib/rake_deploy.rb', line 46

def indifferent_hash_access(name)
  @options[name.to_s] || @options[name]
end

#missing_option(name) ⇒ Object

Raises:



60
61
62
# File 'lib/rake_deploy.rb', line 60

def missing_option(name)
  raise Error.new("Missing option #{name}")
end

#rsyncObject



68
69
70
71
# File 'lib/rake_deploy.rb', line 68

def rsync
  _stdin, @stdout, @stderr, @wait_thr = Open3.popen3(rsync_command)
  write_output
end

#rsync_commandObject



88
89
90
# File 'lib/rake_deploy.rb', line 88

def rsync_command
  "rsync -r #{rsync_options} #{source} #{user}@#{domain}:#{target_dir}"
end

#rsync_optionsObject



64
65
66
# File 'lib/rake_deploy.rb', line 64

def rsync_options
  indifferent_hash_access(:rsync_options).to_a.join(' ')
end

#write_if_exists(io) ⇒ Object



79
80
81
82
# File 'lib/rake_deploy.rb', line 79

def write_if_exists(io)
  op = io.read
  puts op unless op.empty?
end

#write_outputObject



73
74
75
76
77
# File 'lib/rake_deploy.rb', line 73

def write_output
  write_if_exists(@stdout)
  write_if_exists(@stderr)
  puts "Deploying #{name} #{exitstatus}."
end