nsync 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +14 -0
- data/VERSION +1 -1
- data/lib/nsync/active_record/producer/methods.rb +0 -2
- data/lib/nsync/consumer.rb +18 -4
- data/nsync.gemspec +2 -2
- data/test/helper.rb +9 -0
- data/test/nsync_config_test.rb +1 -1
- data/test/nsync_consumer_test.rb +74 -30
- data/test/nsync_producer_test.rb +1 -1
- data/test/repo.rb +1 -1
- metadata +3 -3
data/Rakefile
CHANGED
@@ -45,3 +45,17 @@ end
|
|
45
45
|
|
46
46
|
require 'yard'
|
47
47
|
YARD::Rake::YardocTask.new
|
48
|
+
|
49
|
+
require 'metric_fu'
|
50
|
+
MetricFu::Configuration.run do |config|
|
51
|
+
config.metrics -= [:rcov, :saikuro]
|
52
|
+
config.graphs -= [:rcov, :saikuro]
|
53
|
+
end
|
54
|
+
|
55
|
+
class MetricFu::Template
|
56
|
+
def file_url(name, line)
|
57
|
+
@commit ||= `git rev-parse --verify HEAD`.chomp
|
58
|
+
"http://github.com/schleyfox/nsync/blob/#{@commit}/#{name}#{(line)? "#L#{line}" : ""}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/nsync/consumer.rb
CHANGED
@@ -101,14 +101,17 @@ module Nsync
|
|
101
101
|
|
102
102
|
if config.ordering
|
103
103
|
config.ordering.each do |klass|
|
104
|
-
begin
|
105
|
-
|
104
|
+
klass = begin
|
105
|
+
klass.constantize
|
106
|
+
rescue NameError => e
|
107
|
+
config.log.warn("[NSYNC] Could not find class '#{klass}' from ordering; skipping")
|
108
|
+
false
|
109
|
+
end
|
110
|
+
if klass
|
106
111
|
changes = changeset[klass]
|
107
112
|
if changes
|
108
113
|
apply_changes_for_class(klass, changes)
|
109
114
|
end
|
110
|
-
rescue NameError
|
111
|
-
config.log.warn("[NSYNC] Could not find class '#{klass}' from ordering; skipping")
|
112
115
|
end
|
113
116
|
end
|
114
117
|
else
|
@@ -164,6 +167,7 @@ module Nsync
|
|
164
167
|
# @param [Class] klass
|
165
168
|
# @param [Proc] l
|
166
169
|
def after_class_finished(klass, l)
|
170
|
+
config.log.info("[NSYNC] Added callback to run after class '#{klass}'")
|
167
171
|
@after_class_finished_queues[klass] ||= []
|
168
172
|
@after_class_finished_queues[klass] << l
|
169
173
|
end
|
@@ -184,10 +188,17 @@ module Nsync
|
|
184
188
|
#
|
185
189
|
# @param [Proc] l
|
186
190
|
def after_finished(l)
|
191
|
+
config.log.info("[NSYNC] Added callback to run at the end of the update")
|
187
192
|
@after_finished_queue ||= []
|
188
193
|
@after_finished_queue << l
|
189
194
|
end
|
190
195
|
|
196
|
+
# Lists the configured data remotes in the repo
|
197
|
+
def remotes
|
198
|
+
repo.git.remote({:v => true}).split("\n").map do |line|
|
199
|
+
line.split(/\s+/)
|
200
|
+
end
|
201
|
+
end
|
191
202
|
protected
|
192
203
|
def get_or_create_repo
|
193
204
|
if config.local? || File.exists?(config.repo_path)
|
@@ -245,11 +256,13 @@ module Nsync
|
|
245
256
|
end
|
246
257
|
|
247
258
|
def clear_queues
|
259
|
+
config.log.info("[NSYNC] Callback queues cleared")
|
248
260
|
@after_class_finished_queues = {}
|
249
261
|
@after_finished_queue = []
|
250
262
|
end
|
251
263
|
|
252
264
|
def run_after_class_finished(klass)
|
265
|
+
config.log.info("[NSYNC] Running callbacks for after class '#{klass}'")
|
253
266
|
queue = @after_class_finished_queues[klass]
|
254
267
|
if queue
|
255
268
|
queue.each do |l|
|
@@ -259,6 +272,7 @@ module Nsync
|
|
259
272
|
end
|
260
273
|
|
261
274
|
def run_after_finished
|
275
|
+
config.log.info("[NSYNC] Running callbacks for the end of the update")
|
262
276
|
if @after_finished_queue
|
263
277
|
@after_finished_queue.each do |l|
|
264
278
|
l.call
|
data/nsync.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{nsync}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
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{
|
12
|
+
s.date = %q{2011-01-05}
|
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.}
|
data/test/helper.rb
CHANGED
@@ -6,6 +6,15 @@ require 'mocha'
|
|
6
6
|
require 'shoulda'
|
7
7
|
require 'redgreen'
|
8
8
|
|
9
|
+
#hack for Mac OS X
|
10
|
+
if File.directory?("/private/tmp")
|
11
|
+
TMP_DIR = "/private/tmp"
|
12
|
+
elsif File.directory?("/tmp")
|
13
|
+
TMP_DIR = "/tmp"
|
14
|
+
else
|
15
|
+
raise "Couldn't find a valid tmp dir"
|
16
|
+
end
|
17
|
+
|
9
18
|
require File.join(File.dirname(__FILE__), "repo")
|
10
19
|
require File.join(File.dirname(__FILE__), "classes")
|
11
20
|
|
data/test/nsync_config_test.rb
CHANGED
@@ -73,7 +73,7 @@ class NsyncConfigTest < Test::Unit::TestCase
|
|
73
73
|
|
74
74
|
context "Lock" do
|
75
75
|
setup do
|
76
|
-
@lock_file = "/
|
76
|
+
@lock_file = "#{TMP_DIR}/nsync_test_#{Process.pid}.lock"
|
77
77
|
FileUtils.rm @lock_file, :force => true
|
78
78
|
Nsync.config.lock_file = @lock_file
|
79
79
|
end
|
data/test/nsync_consumer_test.rb
CHANGED
@@ -4,7 +4,7 @@ class NsyncConsumerTest < Test::Unit::TestCase
|
|
4
4
|
def setup
|
5
5
|
Nsync.reset_config
|
6
6
|
#Grit.debug = true
|
7
|
-
@lock_file = "/
|
7
|
+
@lock_file = "#{TMP_DIR}/nsync_test_#{Process.pid}.lock"
|
8
8
|
FileUtils.rm @lock_file, :force => true
|
9
9
|
Nsync.config.lock_file = @lock_file
|
10
10
|
|
@@ -42,7 +42,7 @@ class NsyncConsumerTest < Test::Unit::TestCase
|
|
42
42
|
|
43
43
|
context "that doesn't exist" do
|
44
44
|
setup do
|
45
|
-
@repo_path = "/
|
45
|
+
@repo_path = "#{TMP_DIR}/nsync_non_existent_test_repo"
|
46
46
|
FileUtils.rm_rf @repo_path
|
47
47
|
|
48
48
|
Nsync.config.repo_path = @repo_path
|
@@ -71,8 +71,8 @@ class NsyncConsumerTest < Test::Unit::TestCase
|
|
71
71
|
context "for a remote repo" do
|
72
72
|
context "where the origin does not exist" do
|
73
73
|
setup do
|
74
|
-
@repo_url = "/
|
75
|
-
@repo_path = "/
|
74
|
+
@repo_url = "#{TMP_DIR}/nsync_non_existent_test_repo"
|
75
|
+
@repo_path = "#{TMP_DIR}/nsync_non_existent_test_repo_consumer.git"
|
76
76
|
FileUtils.rm_rf @repo_url
|
77
77
|
FileUtils.rm_rf @repo_path
|
78
78
|
|
@@ -87,23 +87,33 @@ class NsyncConsumerTest < Test::Unit::TestCase
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
@repo = TestRepo.new
|
93
|
-
FileUtils.rm_rf @repo.bare_consumer_repo_path
|
94
|
-
|
95
|
-
Nsync.config.repo_url = @repo.repo_path
|
96
|
-
Nsync.config.repo_path = @repo.bare_consumer_repo_path
|
90
|
+
[['local disk', nil],
|
91
|
+
['github', 'git://github.com/schleyfox/test_repo.git']].each do |name, url|
|
97
92
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
93
|
+
context "where the origin does exist on #{name}" do
|
94
|
+
setup do
|
95
|
+
@repo = TestRepo.new
|
96
|
+
FileUtils.rm_rf @repo.bare_consumer_repo_path
|
97
|
+
|
98
|
+
Nsync.config.repo_url = url || @repo.repo_path
|
99
|
+
Nsync.config.repo_path = @repo.bare_consumer_repo_path
|
100
|
+
|
101
|
+
@consumer = Nsync::Consumer.new
|
102
|
+
end
|
103
|
+
|
104
|
+
should "assign repo to a new bare repo" do
|
105
|
+
assert @consumer.repo.is_a? Grit::Repo
|
106
|
+
assert @consumer.repo.bare
|
107
|
+
end
|
108
|
+
|
109
|
+
should "set the origin remote" do
|
110
|
+
origin = @consumer.remotes.detect{|r| r[0] == "origin" && r[2] == "(fetch)" }
|
111
|
+
assert origin
|
112
|
+
assert_equal Nsync.config.repo_url, origin[1]
|
113
|
+
end
|
104
114
|
end
|
105
|
-
end
|
106
|
-
end
|
115
|
+
end
|
116
|
+
end
|
107
117
|
end
|
108
118
|
|
109
119
|
context "Updating the Consumer side" do
|
@@ -147,21 +157,55 @@ class NsyncConsumerTest < Test::Unit::TestCase
|
|
147
157
|
end
|
148
158
|
|
149
159
|
context "with ordering" do
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
160
|
+
context "the changes" do
|
161
|
+
setup do
|
162
|
+
changeset = {NsyncTestFoo => ["changes"], NsyncTestBar => ["changes"]}
|
163
|
+
|
164
|
+
order = states('order').starts_as('bar')
|
165
|
+
|
166
|
+
Nsync.config.ordering = ["NsyncTestBar", "NsyncTestFoo"]
|
167
|
+
@consumer.repo.expects(:diff).returns(:diffs).once
|
168
|
+
@consumer.expects(:changeset_from_diffs).with(:diffs).returns(changeset).once
|
169
|
+
|
170
|
+
@consumer.expects(:apply_changes_for_class).when(order.is('bar')).with(NsyncTestBar, ["changes"]).then(order.is('foo')).once
|
171
|
+
@consumer.expects(:apply_changes_for_class).when(order.is('foo')).with(NsyncTestFoo, ["changes"]).then(order.is('final')).once
|
172
|
+
end
|
173
|
+
|
174
|
+
should "execute in specified order" do
|
175
|
+
@consumer.update
|
176
|
+
end
|
177
|
+
end
|
154
178
|
|
155
|
-
|
156
|
-
|
157
|
-
|
179
|
+
context "when the class in ordering is not found" do
|
180
|
+
setup do
|
181
|
+
Nsync.config.ordering = ["NsyncTestBlahBlah"]
|
182
|
+
@consumer.repo.expects(:diff).returns(:diffs).once
|
183
|
+
@consumer.expects(:changeset_from_diffs).with(:diffs).returns({}).once
|
184
|
+
@consumer.expects(:apply_changes_for_class).never
|
185
|
+
end
|
158
186
|
|
159
|
-
|
160
|
-
|
187
|
+
should "not error out" do
|
188
|
+
assert_nothing_raised do
|
189
|
+
@consumer.update
|
190
|
+
end
|
191
|
+
end
|
161
192
|
end
|
162
193
|
|
163
|
-
|
164
|
-
|
194
|
+
context "when a NameError occurs for something other than the class" do
|
195
|
+
setup do
|
196
|
+
changeset = {NsyncTestFoo => ["changes"], NsyncTestBar => ["changes"]}
|
197
|
+
Nsync.config.ordering = ["NsyncTestBar", "NsyncTestFoo"]
|
198
|
+
@consumer.repo.expects(:diff).returns(:diffs).once
|
199
|
+
@consumer.expects(:changeset_from_diffs).with(:diffs).returns(changeset).once
|
200
|
+
@consumer.expects(:apply_changes_for_class).
|
201
|
+
raises(NoMethodError, "undefined method `foo' for nil:NilClass")
|
202
|
+
end
|
203
|
+
|
204
|
+
should "raise the error" do
|
205
|
+
assert_raise NoMethodError do
|
206
|
+
@consumer.update
|
207
|
+
end
|
208
|
+
end
|
165
209
|
end
|
166
210
|
end
|
167
211
|
|
data/test/nsync_producer_test.rb
CHANGED
@@ -4,7 +4,7 @@ class NsyncProducerTest < Test::Unit::TestCase
|
|
4
4
|
def setup
|
5
5
|
#Grit.debug = true
|
6
6
|
Nsync.reset_config
|
7
|
-
@lock_file = "/
|
7
|
+
@lock_file = "#{TMP_DIR}/nsync_test_#{Process.pid}.lock"
|
8
8
|
FileUtils.rm @lock_file, :force => true
|
9
9
|
Nsync.config.lock_file = @lock_file
|
10
10
|
end
|
data/test/repo.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ben Hughes
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-01-05 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|