Class: Rbfs::Rsync
- Inherits:
-
Object
- Object
- Rbfs::Rsync
- Defined in:
- lib/rbfs/rsync.rb
Instance Method Summary collapse
- #command(cmd, options = [], &block) ⇒ Object
-
#initialize(config = {}, host = nil) ⇒ Rsync
constructor
A new instance of Rsync.
- #local_root ⇒ Object
- #logger ⇒ Object
- #mkdir ⇒ Object
- #remote_url ⇒ Object
- #rsync ⇒ Object
- #run_command(cmd, &block) ⇒ Object
- #sync ⇒ Object
Constructor Details
#initialize(config = {}, host = nil) ⇒ Rsync
Returns a new instance of Rsync.
5 6 7 8 |
# File 'lib/rbfs/rsync.rb', line 5 def initialize(config = {}, host = nil) @config = config @host = host end |
Instance Method Details
#command(cmd, options = [], &block) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/rbfs/rsync.rb', line 47 def command(cmd, = [], &block) cmd_line = "#{cmd} " cmd_line += .join(' ') output = run_command(cmd_line, &block) exitcode = $? {:output => output, :exitcode => exitcode} end |
#local_root ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/rbfs/rsync.rb', line 18 def local_root if File.directory?(@config[:root]) @config[:root] + "/" else @config[:root] end end |
#logger ⇒ Object
10 11 12 |
# File 'lib/rbfs/rsync.rb', line 10 def logger @config[:logger] end |
#mkdir ⇒ Object
26 27 28 29 |
# File 'lib/rbfs/rsync.rb', line 26 def mkdir args = [@host.ip, "mkdir", "-p", @config[:remote_root]] command("ssh", args) end |
#remote_url ⇒ Object
14 15 16 |
# File 'lib/rbfs/rsync.rb', line 14 def remote_url "#{@host.ip}:#{@config[:remote_root]}" end |
#rsync ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/rbfs/rsync.rb', line 31 def rsync args = ["-a", "--delete"] args << "-e #{@config[:shell]}" if @config[:shell] args << "-v" if @config[:verbose] args << "-n" if @config[:dry] args << "--timeout=#{@config[:timeout]}" if @config[:timeout] ::Rsync.run(local_root, remote_url, args) end |
#run_command(cmd, &block) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/rbfs/rsync.rb', line 55 def run_command(cmd, &block) if block_given? IO.popen("#{cmd} 2>&1", &block) else `#{cmd} 2>&1` end end |
#sync ⇒ Object
40 41 42 43 44 45 |
# File 'lib/rbfs/rsync.rb', line 40 def sync if File.directory?(@config[:root]) mkdir end rsync end |