nsync 0.3.0 → 0.4.0
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/Rakefile +0 -2
- data/VERSION +1 -1
- data/lib/nsync/producer.rb +41 -7
- data/nsync.gemspec +31 -31
- data/test/nsync_producer_test.rb +9 -5
- metadata +7 -28
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/nsync/producer.rb
CHANGED
@@ -36,7 +36,9 @@ module Nsync
|
|
36
36
|
#
|
37
37
|
# @param [String] filename path in the working tree to write to
|
38
38
|
# @param [Hash] hash a hash that can be converted to json to be written
|
39
|
-
|
39
|
+
# @param [Boolean] add tells whether to git add the file.
|
40
|
+
# This is for internal bookkeeping files only
|
41
|
+
def write_file(filename, hash, add=false)
|
40
42
|
config.cd do
|
41
43
|
dir = File.dirname(filename)
|
42
44
|
unless [".", "/"].include?(dir) || File.directory?(dir)
|
@@ -46,7 +48,7 @@ module Nsync
|
|
46
48
|
File.open(File.join(config.repo_path, filename), "w") do |f|
|
47
49
|
f.write( (hash.is_a?(Hash))? hash.to_json : hash )
|
48
50
|
end
|
49
|
-
repo.add(File.join(config.repo_path, filename))
|
51
|
+
repo.add(File.join(config.repo_path, filename)) if add
|
50
52
|
config.log.info("[NSYNC] Updated file '#{filename}'")
|
51
53
|
end
|
52
54
|
true
|
@@ -59,7 +61,8 @@ module Nsync
|
|
59
61
|
end
|
60
62
|
|
61
63
|
def latest_changes
|
62
|
-
diff = repo.git.native('diff', {:full_index => true
|
64
|
+
diff = repo.git.native('diff', {:full_index => true})
|
65
|
+
diff += diff_untracked_files
|
63
66
|
|
64
67
|
if diff =~ /diff --git a/
|
65
68
|
diff = diff.sub(/.*?(diff --git a)/m, '\1')
|
@@ -71,11 +74,42 @@ module Nsync
|
|
71
74
|
changeset_from_diffs(diffs)
|
72
75
|
end
|
73
76
|
|
77
|
+
# gets untracked files into the diff output
|
78
|
+
# hack from http://stackoverflow.com/questions/855767/can-i-use-git-diff-on-untracked-files
|
79
|
+
def diff_untracked_files
|
80
|
+
response, err = repo.git.sh(<<-CMD)
|
81
|
+
git --git-dir='#{repo.git.git_dir}' ls-files -d --others --exclude-standard |
|
82
|
+
while read -r i; do git --git-dir='#{repo.git.git_dir}' diff -- /dev/null "$i"; done
|
83
|
+
CMD
|
84
|
+
response
|
85
|
+
end
|
86
|
+
|
87
|
+
|
74
88
|
# Commits and pushes the current changeset
|
75
|
-
|
89
|
+
#
|
90
|
+
# By default all changes in working dir are committed.
|
91
|
+
#
|
92
|
+
# Alternatively, specific changes can be specified in the
|
93
|
+
# which_changes parameter. The format for this is {"klass" => [id,...]}
|
94
|
+
def commit(message="Friendly data update", which_changes=:all)
|
76
95
|
config.lock do
|
77
96
|
config.cd do
|
78
|
-
|
97
|
+
|
98
|
+
files_to_commit = []
|
99
|
+
latest_changes.each do |klass, changes|
|
100
|
+
which_of_class = which_changes[klass.to_s] if which_changes.is_a?(Hash)
|
101
|
+
changes.each do |change|
|
102
|
+
if which_changes == :all ||
|
103
|
+
(which_of_class && which_of_class.include?(change.id))
|
104
|
+
|
105
|
+
files_to_commit <<
|
106
|
+
File.join(config.repo_path, diff_path(change.diff))
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
repo.git.update_index({:add => true, :remove => true}, '--', *files_to_commit)
|
111
|
+
|
112
|
+
repo.commit_index(message)
|
79
113
|
config.log.info("[NSYNC] Committed '#{message}' to repo")
|
80
114
|
end
|
81
115
|
end
|
@@ -122,7 +156,7 @@ module Nsync
|
|
122
156
|
|
123
157
|
config.lock do
|
124
158
|
self.repo = Grit::Repo.init(config.repo_path)
|
125
|
-
write_file(".gitignore", "")
|
159
|
+
write_file(".gitignore", "", true)
|
126
160
|
end
|
127
161
|
commit("Initial Commit")
|
128
162
|
end
|
@@ -134,7 +168,7 @@ module Nsync
|
|
134
168
|
|
135
169
|
# refinement to allow the producer to consume itself
|
136
170
|
if classes.empty?
|
137
|
-
classes = [CoreExtensions.constantize(producer_class_name)].compact
|
171
|
+
classes = [(CoreExtensions.constantize(producer_class_name) rescue nil)].compact
|
138
172
|
end
|
139
173
|
[classes, id]
|
140
174
|
end
|
data/nsync.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
@@ -9,52 +9,51 @@ Gem::Specification.new do |s|
|
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ben Hughes"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-10-28}
|
13
13
|
s.description = %q{Nsync is designed to allow you to have a separate data
|
14
14
|
processing app with its own data processing optimized database and a consumer
|
15
15
|
app with its own database, while keeping the data as in sync as you want it.}
|
16
16
|
s.email = %q{ben@pixelmachine.org}
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE",
|
19
|
-
|
19
|
+
"README.md"
|
20
20
|
]
|
21
21
|
s.files = [
|
22
22
|
"LICENSE",
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"jeweler_monkey_patch.rb",
|
27
|
+
"lib/nsync.rb",
|
28
|
+
"lib/nsync/active_record/consumer/methods.rb",
|
29
|
+
"lib/nsync/active_record/methods.rb",
|
30
|
+
"lib/nsync/active_record/producer/methods.rb",
|
31
|
+
"lib/nsync/class_methods.rb",
|
32
|
+
"lib/nsync/config.rb",
|
33
|
+
"lib/nsync/consumer.rb",
|
34
|
+
"lib/nsync/core_extensions.rb",
|
35
|
+
"lib/nsync/git_version_manager.rb",
|
36
|
+
"lib/nsync/producer.rb",
|
37
|
+
"lib/nsync/producer/methods.rb",
|
38
|
+
"nsync.gemspec",
|
39
|
+
"test/active_record_test.rb",
|
40
|
+
"test/classes.rb",
|
41
|
+
"test/helper.rb",
|
42
|
+
"test/nsync_config_test.rb",
|
43
|
+
"test/nsync_consumer_test.rb",
|
44
|
+
"test/nsync_producer_test.rb",
|
45
|
+
"test/repo.rb"
|
39
46
|
]
|
40
47
|
s.homepage = %q{http://github.com/schleyfox/nsync}
|
41
48
|
s.require_paths = ["lib"]
|
42
|
-
s.rubygems_version = %q{1.
|
49
|
+
s.rubygems_version = %q{1.3.6}
|
43
50
|
s.summary = %q{Keep your data processors and apps in sync}
|
44
|
-
s.test_files = [
|
45
|
-
"test/active_record_test.rb",
|
46
|
-
"test/classes.rb",
|
47
|
-
"test/helper.rb",
|
48
|
-
"test/nsync_config_test.rb",
|
49
|
-
"test/nsync_consumer_test.rb",
|
50
|
-
"test/nsync_producer_test.rb",
|
51
|
-
"test/repo.rb"
|
52
|
-
]
|
53
51
|
|
54
52
|
if s.respond_to? :specification_version then
|
53
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
55
54
|
s.specification_version = 3
|
56
55
|
|
57
|
-
if Gem::Version.new(Gem::
|
56
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
58
57
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
59
58
|
s.add_runtime_dependency(%q<schleyfox-grit>, [">= 2.3.0.1"])
|
60
59
|
s.add_runtime_dependency(%q<schleyfox-lockfile>, [">= 1.0.0"])
|
@@ -75,3 +74,4 @@ Gem::Specification.new do |s|
|
|
75
74
|
s.add_dependency(%q<mocha>, [">= 0"])
|
76
75
|
end
|
77
76
|
end
|
77
|
+
|
data/test/nsync_producer_test.rb
CHANGED
@@ -32,7 +32,7 @@ class NsyncProducerTest < Test::Unit::TestCase
|
|
32
32
|
|
33
33
|
should "initialize it and make a base commit" do
|
34
34
|
Grit::Repo.expects(:init).with(@repo_path).once
|
35
|
-
Nsync::Producer.any_instance.expects(:write_file).with(".gitignore", "").once
|
35
|
+
Nsync::Producer.any_instance.expects(:write_file).with(".gitignore", "", true).once
|
36
36
|
Nsync::Producer.any_instance.expects(:commit).returns(true).once
|
37
37
|
Nsync::Producer.new
|
38
38
|
end
|
@@ -74,9 +74,8 @@ class NsyncProducerTest < Test::Unit::TestCase
|
|
74
74
|
end
|
75
75
|
|
76
76
|
should "write the file to disk, add it to the index, but not commit" do
|
77
|
-
@producer.repo.expects(:add).with(File.join(@repo.repo_path, @file)).once
|
78
77
|
@producer.expects(:commit).never
|
79
|
-
@producer.repo.expects(:
|
78
|
+
@producer.repo.expects(:commit_index).never
|
80
79
|
@producer.write_file(@file, @hash)
|
81
80
|
|
82
81
|
assert_equal JSON.load(File.read(File.join(@repo.repo_path, @file))), @hash
|
@@ -92,7 +91,6 @@ class NsyncProducerTest < Test::Unit::TestCase
|
|
92
91
|
|
93
92
|
should "behave just like a create" do
|
94
93
|
new_hash = {"id" => 1, "val" => "Kaboom"}
|
95
|
-
@producer.repo.expects(:add).with(File.join(@repo.repo_path, @file)).once
|
96
94
|
@producer.expects(:commit).never
|
97
95
|
@producer.write_file(@file, new_hash)
|
98
96
|
|
@@ -121,7 +119,8 @@ class NsyncProducerTest < Test::Unit::TestCase
|
|
121
119
|
|
122
120
|
should "commit all changes as well as push" do
|
123
121
|
@msg = "Test Update"
|
124
|
-
@producer.repo.expects(:
|
122
|
+
@producer.repo.git.expects(:update_index).once
|
123
|
+
@producer.repo.expects(:commit_index).with(@msg).once
|
125
124
|
@producer.expects(:push).once
|
126
125
|
@producer.commit(@msg)
|
127
126
|
end
|
@@ -256,6 +255,11 @@ class NsyncProducerTest < Test::Unit::TestCase
|
|
256
255
|
|
257
256
|
assert_equal 4, @repo.commits.size
|
258
257
|
assert_equal 4, @remote_repo.commits.size
|
258
|
+
|
259
|
+
@producer.write_file("nsync_test_bar/5.json", {:id => 5, :val => "Changed"})
|
260
|
+
@producer.write_file("nsync_test_bar/6.json", {:id => 6, :val => "Added file"})
|
261
|
+
@repo.git.expects(:update_index).with({:add => true, :remove => true}, '--', File.join(@repo_path, 'nsync_test_bar/6.json')).once
|
262
|
+
@producer.commit("Partial commit", {'NsyncTestBar' => ['6']})
|
259
263
|
end
|
260
264
|
end
|
261
265
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nsync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
7
|
+
- 4
|
9
8
|
- 0
|
10
|
-
version: 0.
|
9
|
+
version: 0.4.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Ben Hughes
|
@@ -15,18 +14,16 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-
|
17
|
+
date: 2011-10-28 00:00:00 -04:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: json
|
23
22
|
prerelease: false
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
24
|
requirements:
|
27
25
|
- - ">="
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
27
|
segments:
|
31
28
|
- 0
|
32
29
|
version: "0"
|
@@ -36,11 +33,9 @@ dependencies:
|
|
36
33
|
name: schleyfox-grit
|
37
34
|
prerelease: false
|
38
35
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
36
|
requirements:
|
41
37
|
- - ">="
|
42
38
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 117
|
44
39
|
segments:
|
45
40
|
- 2
|
46
41
|
- 3
|
@@ -53,11 +48,9 @@ dependencies:
|
|
53
48
|
name: schleyfox-lockfile
|
54
49
|
prerelease: false
|
55
50
|
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
51
|
requirements:
|
58
52
|
- - ">="
|
59
53
|
- !ruby/object:Gem::Version
|
60
|
-
hash: 23
|
61
54
|
segments:
|
62
55
|
- 1
|
63
56
|
- 0
|
@@ -69,11 +62,9 @@ dependencies:
|
|
69
62
|
name: shoulda
|
70
63
|
prerelease: false
|
71
64
|
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
65
|
requirements:
|
74
66
|
- - ">="
|
75
67
|
- !ruby/object:Gem::Version
|
76
|
-
hash: 3
|
77
68
|
segments:
|
78
69
|
- 0
|
79
70
|
version: "0"
|
@@ -83,11 +74,9 @@ dependencies:
|
|
83
74
|
name: mocha
|
84
75
|
prerelease: false
|
85
76
|
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
77
|
requirements:
|
88
78
|
- - ">="
|
89
79
|
- !ruby/object:Gem::Version
|
90
|
-
hash: 3
|
91
80
|
segments:
|
92
81
|
- 0
|
93
82
|
version: "0"
|
@@ -140,35 +129,25 @@ rdoc_options: []
|
|
140
129
|
require_paths:
|
141
130
|
- lib
|
142
131
|
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
-
none: false
|
144
132
|
requirements:
|
145
133
|
- - ">="
|
146
134
|
- !ruby/object:Gem::Version
|
147
|
-
hash: 3
|
148
135
|
segments:
|
149
136
|
- 0
|
150
137
|
version: "0"
|
151
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
-
none: false
|
153
139
|
requirements:
|
154
140
|
- - ">="
|
155
141
|
- !ruby/object:Gem::Version
|
156
|
-
hash: 3
|
157
142
|
segments:
|
158
143
|
- 0
|
159
144
|
version: "0"
|
160
145
|
requirements: []
|
161
146
|
|
162
147
|
rubyforge_project:
|
163
|
-
rubygems_version: 1.
|
148
|
+
rubygems_version: 1.3.6
|
164
149
|
signing_key:
|
165
150
|
specification_version: 3
|
166
151
|
summary: Keep your data processors and apps in sync
|
167
|
-
test_files:
|
168
|
-
|
169
|
-
- test/classes.rb
|
170
|
-
- test/helper.rb
|
171
|
-
- test/nsync_config_test.rb
|
172
|
-
- test/nsync_consumer_test.rb
|
173
|
-
- test/nsync_producer_test.rb
|
174
|
-
- test/repo.rb
|
152
|
+
test_files: []
|
153
|
+
|