forked from pitluga/supply_drop
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extracted rsync class, only using ssh keys that exist
- Loading branch information
Showing
4 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Rsync | ||
class << self | ||
def command(from, to, options={}) | ||
flags = ['-az'] | ||
flags << '--delete' if options[:delete] | ||
flags << excludes(options[:excludes]) if options.has_key?(:excludes) | ||
flags << ssh_options(options[:ssh]) if options.has_key?(:ssh) | ||
|
||
"rsync #{flags.compact.join(' ')} #{from} #{to}" | ||
end | ||
|
||
def excludes(patterns) | ||
[patterns].flatten.map { |p| "--exclude=#{p}" } | ||
end | ||
|
||
def ssh_options(options) | ||
mapped_options = options.map do |key, value| | ||
if key == :keys | ||
[value].flatten.select { |k| File.exist?(k) }.map { |k| "-i #{k}" } | ||
end | ||
end | ||
|
||
%[-e "ssh #{mapped_options.join(' ')}"] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'test/unit' | ||
require File.expand_path('../../lib/supply_drop/rsync', __FILE__) | ||
|
||
class RsyncTest < Test::Unit::TestCase | ||
|
||
def test_build_simple_command | ||
command = Rsync.command('bar', 'foo') | ||
assert_equal 'rsync -az bar foo', command | ||
end | ||
|
||
def test_allows_passing_delete | ||
command = Rsync.command('bar', 'foo', :delete => true) | ||
assert_equal 'rsync -az --delete bar foo', command | ||
end | ||
|
||
def test_allows_specifying_an_exclude | ||
command = Rsync.command('bar', 'foo', :excludes => '.git') | ||
assert_equal 'rsync -az --exclude=.git bar foo', command | ||
end | ||
|
||
def test_ssh_options_keys_only_lists_existing_files | ||
command = Rsync.command('.', 'foo', :ssh => { :keys => [__FILE__, "#{__FILE__}dadijofs"] }) | ||
assert_match /-i #{__FILE__}/, command | ||
end | ||
|
||
end |