ruby-unison 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,24 +1,42 @@
1
1
  # ruby-unison
2
2
 
3
3
  Ruby interface of the command of file synchronizer [unison](http://www.cis.upenn.edu/~bcpierce/unison/).
4
+ ruby-unison defines UnisonCommand class to execute unison in unison.rb.
5
+
6
+ ## Installation
7
+
8
+ gem install ruby-unison
4
9
 
5
10
  ## Examples
6
11
 
7
12
  ### Basic usage
8
13
 
14
+ require 'unison'
9
15
  uc = UnisonCommand.new("pref", "root1", "root2")
10
16
  uc.execute
17
+
18
+ uc = UnisonCommand.new("root1", "root2")
19
+ uc.execute
11
20
 
12
21
  ### Dry run
13
22
 
23
+ require 'unison'
14
24
  uc = UnisonCommand.new("pref", "root1", "root2")
15
25
  uc.execute(true)
16
26
 
17
27
  ### Usage of unison options
18
28
 
29
+ require 'unison'
19
30
  uc = UnisonCommand.new("root1", "root2", :force => "root2", :path => ["Document", "Desktop"], :auto => true)
20
31
  uc.execute
21
32
 
33
+ ### Change of unison path
34
+
35
+ require 'unison'
36
+ uc = UnisonCommand.new("root1", "root2")
37
+ uc.command = "/path/to/unison"
38
+ uc.execute
39
+
22
40
  ## Contributing to ruby-unison
23
41
 
24
42
  - Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
data/lib/unison.rb CHANGED
@@ -76,19 +76,21 @@ class UnisonCommand
76
76
  class InvalidOption < StandardError
77
77
  end
78
78
 
79
- class NonExsistentOption < StandardError
79
+ class NonExistentOption < StandardError
80
80
  end
81
81
 
82
82
  attr_accessor :profile, :root1, :root2, :option, :command
83
83
 
84
84
  # +args+ accepts the following three pattern:
85
- # - root1, root2, opts = {}
86
- # - profilename, opts = {}
87
- # - profilename, root1, root2, opts = {}
85
+ # - root1, root2, opts = \{\}
86
+ # - profilename, opts = \{\}
87
+ # - profilename, root1, root2, opts = \{\}
88
88
  # We set option of unison command to optinal hash.
89
89
  # The keys are symbols made from hypen-removed options of unison command and
90
90
  # the values are booleans (true or false), strings, and arrays of strings
91
91
  # corresponding to unison's options.
92
+ # Note that to set boolean option we do not use a string 'true' or 'false',
93
+ # but we use TrueClass, FalseClass, or NilClass.
92
94
  def initialize(*args)
93
95
  if Hash === args[-1]
94
96
  @option = args[-1]
@@ -122,8 +124,15 @@ class UnisonCommand
122
124
  if spec = UNISON_OPTION_SPEC[key.intern]
123
125
  case spec
124
126
  when :bool
125
- if val
126
- cmd << "-#{key}"
127
+ case val
128
+ when TrueClass, FalseClass, NilClass
129
+ if val
130
+ cmd << "-#{key}"
131
+ else
132
+ cmd << "-#{key}=false"
133
+ end
134
+ else
135
+ raise UnisonCommand::InvalidOption, "We use TrueClass, FalseClass, or NilClass for #{key}."
127
136
  end
128
137
  when :array
129
138
  k = "-#{key}"
@@ -144,7 +153,7 @@ class UnisonCommand
144
153
  cmd << "-#{key}" << v
145
154
  end
146
155
  else
147
- raise UnisonCommand::NonExsistentOption, "Nonexistent unison option: #{key.to_s}"
156
+ raise UnisonCommand::NonExistentOption, "Nonexistent unison option: #{key.to_s}"
148
157
  end
149
158
  end
150
159
  cmd.compact!
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ruby-unison}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Takayuki YAMAGUCHI"]
12
+ s.date = %q{2011-05-12}
13
+ s.description = %q{Ruby interface of the command of file synchronizer unison}
14
+ s.email = %q{d@ytak.info}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/unison.rb",
29
+ "ruby-unison.gemspec",
30
+ "spec/spec_helper.rb",
31
+ "spec/unison_spec.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/ytaka/ruby-unison}
34
+ s.licenses = ["GPLv3"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.6.2}
37
+ s.summary = %q{ruby-unison}
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_development_dependency(%q<rspec>, [">= 2.5.0"])
44
+ s.add_development_dependency(%q<yard>, [">= 0.6.0"])
45
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
46
+ s.add_development_dependency(%q<jeweler>, [">= 1.6.0"])
47
+ s.add_development_dependency(%q<rcov>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<rspec>, [">= 2.5.0"])
50
+ s.add_dependency(%q<yard>, [">= 0.6.0"])
51
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
52
+ s.add_dependency(%q<jeweler>, [">= 1.6.0"])
53
+ s.add_dependency(%q<rcov>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<rspec>, [">= 2.5.0"])
57
+ s.add_dependency(%q<yard>, [">= 0.6.0"])
58
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, [">= 1.6.0"])
60
+ s.add_dependency(%q<rcov>, [">= 0"])
61
+ end
62
+ end
63
+
data/spec/unison_spec.rb CHANGED
@@ -20,6 +20,11 @@ describe UnisonCommand do
20
20
  uc.execute(true).should == ["unison", "pref", "root1", "root2", "-auto"]
21
21
  end
22
22
 
23
+ it "should return unison command with a boolean option false" do
24
+ uc = UnisonCommand.new("pref", "root1", "root2", :auto => false)
25
+ uc.execute(true).should == ["unison", "pref", "root1", "root2", "-auto=false"]
26
+ end
27
+
23
28
  it "should return unison command with two arguments and a boolean option" do
24
29
  uc = UnisonCommand.new("root1", "root2", :auto => true)
25
30
  uc.execute(true).should == ["unison", "root1", "root2", "-auto"]
@@ -51,4 +56,30 @@ describe UnisonCommand do
51
56
  "-path", "Document", "-path", "Desktop", "-auto"]
52
57
  end
53
58
 
59
+ it "should raise UnisonCommand::InvalidOption" do
60
+ uc = UnisonCommand.new("root1", "root2", :backuplocation => "invalid")
61
+ lambda do
62
+ uc.execute
63
+ end.should raise_error(UnisonCommand::InvalidOption)
64
+ end
65
+
66
+ it "should raise UnisonCommand::InvalidOption" do
67
+ uc = UnisonCommand.new("root1", "root2", :auto => 'true')
68
+ lambda do
69
+ uc.execute
70
+ end.should raise_error(UnisonCommand::InvalidOption)
71
+ end
72
+
73
+ it "should raise UnisonCommand::NonExistentOption" do
74
+ uc = UnisonCommand.new("root1", "root2", :autoo => true)
75
+ lambda do
76
+ uc.execute
77
+ end.should raise_error(UnisonCommand::NonExistentOption)
78
+ end
79
+
80
+ it "should change unison path" do
81
+ uc = UnisonCommand.new("root1", "root2")
82
+ uc.command = "/usr/local/bin/unison"
83
+ uc.execute(true).should == ["/usr/local/bin/unison", "root1", "root2"]
84
+ end
54
85
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ruby-unison
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.0
5
+ version: 0.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Takayuki YAMAGUCHI
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-11 00:00:00 +09:00
13
+ date: 2011-05-12 00:00:00 +09:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -87,6 +87,7 @@ files:
87
87
  - Rakefile
88
88
  - VERSION
89
89
  - lib/unison.rb
90
+ - ruby-unison.gemspec
90
91
  - spec/spec_helper.rb
91
92
  - spec/unison_spec.rb
92
93
  has_rdoc: true
@@ -103,7 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
104
  requirements:
104
105
  - - ">="
105
106
  - !ruby/object:Gem::Version
106
- hash: -2753928633824984509
107
+ hash: -3840236895340394348
107
108
  segments:
108
109
  - 0
109
110
  version: "0"