rsync 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -8,9 +8,17 @@ Ruby/Rsync is a Ruby library that can syncronize files between remote hosts by w
8
8
 
9
9
  ## Usage
10
10
 
11
+ Minimal example
12
+
13
+ require "rsync"
14
+
15
+ result = Rsync.run("/path/to/src", "/path/to/dest")
16
+
17
+ Complete example
18
+
11
19
  require "rsync"
12
20
 
13
- Rsync.command(["/path/to/source", "/path/to/destination"]) do |result|
21
+ Rsync.run("/path/to/src", "/path/to/dest") do |result|
14
22
  if result.success?
15
23
  result.changes.each do |change|
16
24
  puts "#{change.filename} (#{change.summary})"
@@ -5,12 +5,13 @@ require "rsync/result"
5
5
  # The main interface to rsync
6
6
  module Rsync
7
7
  # Creates and runs an rsync {Command} and return the {Result}
8
+ # @param source {String}
9
+ # @param destination {String}
10
+ # @param args {Array}
8
11
  # @return {Result}
9
12
  # @yield {Result}
10
- def self.command(args, &block)
11
- output = Command.new(args).run
12
- exitcode = $?
13
- result = Result.new(output, exitcode)
13
+ def self.run(source, destination, args = [], &block)
14
+ result = Command.run(source, destination, args)
14
15
  yield(result) if block_given?
15
16
  result
16
17
  end
@@ -1,20 +1,18 @@
1
1
  module Rsync
2
2
  # An rsync command to be run
3
3
  class Command
4
- def initialize(args)
5
- @args = args.join(" ")
6
- end
7
-
8
4
  # Runs the rsync job and returns the results
9
5
  #
6
+ # @param args {Array}
10
7
  # @return {Result}
11
- def run
12
- run_command("rsync --itemize-changes #{@args}")
8
+ def self.run(*args)
9
+ output = run_command("rsync --itemize-changes #{args.join(" ")}")
10
+ Result.new(output, $?.exitstatus)
13
11
  end
14
12
 
15
13
  private
16
14
 
17
- def run_command(cmd, &block)
15
+ def self.run_command(cmd, &block)
18
16
  if block_given?
19
17
  IO.popen("#{cmd} 2>&1", &block)
20
18
  else
@@ -10,15 +10,15 @@ module Rsync
10
10
  end
11
11
 
12
12
  # Whether the rsync job was run without errors.
13
- # @return Boolean
13
+ # @return {Boolean}
14
14
  def success?
15
15
  @exitcode.to_i == 0
16
16
  end
17
17
 
18
18
  # The error message based on exit code.
19
- # @return String
19
+ # @return {String}
20
20
  def error
21
- case @exitcode.exitstatus
21
+ case @exitcode.to_i
22
22
  when 0
23
23
  "Success"
24
24
  when 1
@@ -68,10 +68,16 @@ module Rsync
68
68
  #
69
69
  # @return {Array<Change>}
70
70
  def changes
71
+ change_list
72
+ end
73
+
74
+ private
75
+
76
+ def change_list
71
77
  list = []
72
78
  @raw.split("\n").each do |line|
73
79
  #if line =~ /^([<>ch.*][fdLDS][ .+\?cstTpoguax]{9}) (.*)$/
74
- if line =~ /^([<>ch.\*].{10}) (.*)$/
80
+ if line =~ /^([<>ch\.\*].{10}) (.*)$/
75
81
  detail = Change.new(line)
76
82
  list << detail if detail.changed?
77
83
  end
@@ -1,4 +1,4 @@
1
1
  module Rsync
2
2
  # Project version
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
@@ -0,0 +1,7 @@
1
+ require 'rsync/command'
2
+
3
+ describe Rsync::Command do
4
+ it "should work" do
5
+ Rsync::Command.run("/path/to/src/", "/path/to/dest", "-a").should be_kind_of(Rsync::Result)
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ require 'rsync/result'
2
+
3
+ describe Rsync::Result do
4
+ it "should handle basic example" do
5
+ result = Rsync::Result.new("", 0)
6
+ result.changes.should eql([])
7
+ result.error.should eql("Success")
8
+ result.success?.should eql(true)
9
+ end
10
+
11
+ it "should handle basic example with changes" do
12
+ result = Rsync::Result.new(">f......... filename\n", 0)
13
+ result.changes.length.should eql(1)
14
+ result.error.should eql("Success")
15
+ result.success?.should eql(true)
16
+ end
17
+
18
+ it "should handle syntax error" do
19
+ result = Rsync::Result.new("", 1)
20
+ result.changes.should eql([])
21
+ result.error.should eql("Syntax or usage error")
22
+ result.success?.should eql(false)
23
+ end
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-07-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &7909780 !ruby/object:Gem::Requirement
16
+ requirement: &13436720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *7909780
24
+ version_requirements: *13436720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &7909000 !ruby/object:Gem::Requirement
27
+ requirement: &13435920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *7909000
35
+ version_requirements: *13435920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &7908040 !ruby/object:Gem::Requirement
38
+ requirement: &13434940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *7908040
46
+ version_requirements: *13434940
47
47
  description:
48
48
  email:
49
49
  - jbussdieker@gmail.com
@@ -64,6 +64,8 @@ files:
64
64
  - lib/rsync/version.rb
65
65
  - rsync.gemspec
66
66
  - spec/rsync/change_spec.rb
67
+ - spec/rsync/command_spec.rb
68
+ - spec/rsync/result_spec.rb
67
69
  homepage: http://github.com/jbussdieker/ruby-rsync
68
70
  licenses:
69
71
  - MIT
@@ -92,4 +94,6 @@ summary: Ruby/Rsync is a Ruby library that can syncronize files between remote h
92
94
  by wrapping a call to the rsync binary.
93
95
  test_files:
94
96
  - spec/rsync/change_spec.rb
97
+ - spec/rsync/command_spec.rb
98
+ - spec/rsync/result_spec.rb
95
99
  has_rdoc: