synchronisable 0.0.5 → 0.0.6
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.
- checksums.yaml +4 -4
- data/TODO.md +1 -0
- data/lib/synchronisable/dsl/associations.rb +6 -1
- data/lib/synchronisable/dsl/macro.rb +1 -0
- data/lib/synchronisable/input_descriptor.rb +1 -0
- data/lib/synchronisable/{data_builder.rb → input_dispatcher.rb} +10 -11
- data/lib/synchronisable/model.rb +4 -4
- data/lib/synchronisable/source.rb +2 -2
- data/lib/synchronisable/synchronizer.rb +5 -5
- data/lib/synchronisable/synchronizers/synchronizer_default.rb +2 -0
- data/lib/synchronisable/version.rb +1 -1
- data/lib/synchronisable/worker.rb +2 -2
- data/lib/synchronisable.rb +2 -1
- data/spec/models/team_spec.rb +0 -1
- data/spec/synchronisable/dsl/macro_spec.rb +23 -6
- data/spec/synchronisable/support/has_macro_bar.rb +6 -0
- data/spec/synchronisable/support/{has_macro.rb → has_macro_foo.rb} +1 -1
- data/spec/synchronisable/support/has_macro_foo_subclass.rb +9 -0
- metadata +9 -7
- data/spec/synchronisable/support/has_macro_subclass.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6de60703f28fbed5c2a30a924474691bf98c489e
|
4
|
+
data.tar.gz: f5da8cda6005fa932be6ce2a9ecc8eb6a7973053
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 485bd2ca85dcf24fc9ff56cec0442498bfe62cfd523cc220cd2a319fb0d5cde49b574f3e3666af35e126528a46774364a967d0d0e232c8d42f13a3b7687f8c4b
|
7
|
+
data.tar.gz: 68d4ff7a28e5b2952b072cf5bbfa1f8d66c124b8c5bf365f8b958968cd390c48632fbbb54793035ede94e4e061519bbb79ca0519ee63dfd6873e3d3a3bfec14f
|
data/TODO.md
CHANGED
@@ -12,6 +12,11 @@ module Synchronisable
|
|
12
12
|
end
|
13
13
|
|
14
14
|
module ClassMethods
|
15
|
+
def inherited(subclass)
|
16
|
+
super
|
17
|
+
subclass.associations = {}
|
18
|
+
end
|
19
|
+
|
15
20
|
[HasOne, HasMany].each do |klass|
|
16
21
|
macro = klass.to_s.demodulize.underscore.to_sym
|
17
22
|
define_method(macro) do |name, options = {}|
|
@@ -49,7 +54,7 @@ module Synchronisable
|
|
49
54
|
end
|
50
55
|
|
51
56
|
def required_associations
|
52
|
-
self.associations.select { |_, a| a.required }.
|
57
|
+
self.associations.select { |_, a| a.required }.keys
|
53
58
|
end
|
54
59
|
end
|
55
60
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'synchronisable/input_descriptor'
|
2
2
|
|
3
3
|
module Synchronisable
|
4
|
-
|
4
|
+
# @api private
|
5
|
+
class InputDispatcher
|
5
6
|
class << self
|
6
|
-
def
|
7
|
-
new(model, synchronizer).
|
7
|
+
def dispatch(model, synchronizer, data)
|
8
|
+
new(model, synchronizer).dispatch(data)
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
@@ -13,17 +14,17 @@ module Synchronisable
|
|
13
14
|
@synchronizer = synchronizer
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
+
def dispatch(data)
|
17
18
|
input = InputDescriptor.new(data)
|
18
19
|
|
19
|
-
result = case
|
20
|
-
when
|
20
|
+
result = case
|
21
|
+
when input.empty?
|
21
22
|
@synchronizer.fetch
|
22
|
-
when
|
23
|
+
when input.remote_id?
|
23
24
|
@synchronizer.find(data)
|
24
|
-
when
|
25
|
+
when input.local_id?
|
25
26
|
find_by_local_id(data)
|
26
|
-
when
|
27
|
+
when input.array_of_ids?
|
27
28
|
find_by_array_of_ids(input)
|
28
29
|
else
|
29
30
|
result = data.dup
|
@@ -44,8 +45,6 @@ module Synchronisable
|
|
44
45
|
import ? @synchronizer.find(import.remote_id) : nil
|
45
46
|
end
|
46
47
|
|
47
|
-
private
|
48
|
-
|
49
48
|
def find_imports(class_name, ids)
|
50
49
|
case class_name
|
51
50
|
when 'Fixnum'
|
data/lib/synchronisable/model.rb
CHANGED
@@ -41,13 +41,13 @@ module Synchronisable
|
|
41
41
|
def set_defaults(args)
|
42
42
|
options = args.extract_options!
|
43
43
|
|
44
|
-
self.synchronizer = args.first ||
|
45
|
-
|
44
|
+
self.synchronizer = args.first || options[:synchronizer] ||
|
45
|
+
find_synchronizer || SynchronizerDefault
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
48
|
+
def find_synchronizer
|
49
49
|
const_name = "#{self.name.demodulize}#{SYNCHRONIZER_SUFFIX}"
|
50
|
-
const_name.safe_constantize
|
50
|
+
const_name.safe_constantize
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -31,7 +31,7 @@ module Synchronisable
|
|
31
31
|
end
|
32
32
|
|
33
33
|
@import_record = Import.find_by(
|
34
|
-
:remote_id => @remote_id,
|
34
|
+
:remote_id => @remote_id.to_s,
|
35
35
|
:synchronisable_type => @model
|
36
36
|
)
|
37
37
|
|
@@ -51,7 +51,7 @@ module Synchronisable
|
|
51
51
|
@import_record = Import.create!(
|
52
52
|
:synchronisable_id => record.id,
|
53
53
|
:synchronisable_type => @model.to_s,
|
54
|
-
:remote_id => @remote_id,
|
54
|
+
:remote_id => @remote_id.to_s,
|
55
55
|
:attrs => @local_attrs
|
56
56
|
)
|
57
57
|
end
|
@@ -110,10 +110,6 @@ module Synchronisable
|
|
110
110
|
data.present? ? data : gateway_instance.try(:find, id)
|
111
111
|
end
|
112
112
|
|
113
|
-
def gateway_instance
|
114
|
-
@gateway_instance ||= gateway.try(:new, self)
|
115
|
-
end
|
116
|
-
|
117
113
|
# Extracts remote id from given attribute hash.
|
118
114
|
#
|
119
115
|
# @param attrs [Hash] remote attributes
|
@@ -165,12 +161,16 @@ module Synchronisable
|
|
165
161
|
#
|
166
162
|
# @raise [MissedRemoteIdError] raised when data doesn't contain remote id
|
167
163
|
def ensure_remote_id(id)
|
168
|
-
return id if id.present?
|
164
|
+
return id.to_s if id.present?
|
169
165
|
raise MissedRemoteIdError, I18n.t(
|
170
166
|
'errors.missed_remote_id',
|
171
167
|
remote_id: remote_id
|
172
168
|
)
|
173
169
|
end
|
170
|
+
|
171
|
+
def gateway_instance
|
172
|
+
@gateway_instance ||= gateway.try(:new, self)
|
173
|
+
end
|
174
174
|
end
|
175
175
|
end
|
176
176
|
end
|
@@ -2,7 +2,7 @@ require 'colorize'
|
|
2
2
|
|
3
3
|
require 'synchronisable/error_handler'
|
4
4
|
require 'synchronisable/context'
|
5
|
-
require 'synchronisable/
|
5
|
+
require 'synchronisable/input_dispatcher'
|
6
6
|
require 'synchronisable/source'
|
7
7
|
require 'synchronisable/models/import'
|
8
8
|
|
@@ -45,7 +45,7 @@ module Synchronisable
|
|
45
45
|
error_handler = ErrorHandler.new(@logger, context)
|
46
46
|
context.before = @model.imports_count
|
47
47
|
|
48
|
-
hashes =
|
48
|
+
hashes = InputDispatcher.dispatch(@model, @synchronizer, data)
|
49
49
|
hashes.each do |attrs|
|
50
50
|
source = Source.new(@model, @parent, attrs)
|
51
51
|
error_handler.handle(source) do
|
data/lib/synchronisable.rb
CHANGED
@@ -14,6 +14,7 @@ require 'synchronisable/version'
|
|
14
14
|
require 'synchronisable/models/import'
|
15
15
|
require 'synchronisable/synchronizer'
|
16
16
|
require 'synchronisable/model'
|
17
|
+
require 'synchronisable/gateway'
|
17
18
|
|
18
19
|
locale_paths = File.join(File.dirname(__FILE__),
|
19
20
|
'synchronisable', 'locale', '*.yml')
|
@@ -34,7 +35,7 @@ I18n.available_locales = [:en, :ru]
|
|
34
35
|
# Match.sync(:include => {
|
35
36
|
# :match_players => :player
|
36
37
|
# })
|
37
|
-
# Model.sync([id1, ..., idn])
|
38
|
+
# + Model.sync([id1, ..., idn])
|
38
39
|
#
|
39
40
|
# Model.where(condition).sync
|
40
41
|
# Match.where(condition).sync(:include => {
|
data/spec/models/team_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Synchronisable::DSL::Macro do
|
4
4
|
describe 'commom attributes' do
|
5
|
-
subject {
|
5
|
+
subject { HasMacroFoo }
|
6
6
|
|
7
7
|
before do
|
8
8
|
subject.xyz 7
|
@@ -15,6 +15,9 @@ describe Synchronisable::DSL::Macro do
|
|
15
15
|
it { respond_to? :xxx }
|
16
16
|
it { respond_to? :arr }
|
17
17
|
|
18
|
+
it { should_not respond_to? :baz }
|
19
|
+
it { should_not respond_to? :sqr2 }
|
20
|
+
|
18
21
|
its(:foo) { should be nil }
|
19
22
|
its(:bar) { should eq(1) }
|
20
23
|
its(:baz) { should eq(2) }
|
@@ -24,11 +27,14 @@ describe Synchronisable::DSL::Macro do
|
|
24
27
|
|
25
28
|
describe 'attribute with default value lambda that raises an error' do
|
26
29
|
it 'raises error' do
|
27
|
-
expect {
|
30
|
+
expect { HasMacroFoo.carefull }.to raise_error(NotImplementedError)
|
28
31
|
end
|
29
32
|
|
30
33
|
context 'when overriden in subclass not to raise an error' do
|
31
|
-
subject {
|
34
|
+
subject { HasMacroFooSubclass }
|
35
|
+
|
36
|
+
it { should_not respond_to? :baz }
|
37
|
+
it { should_not respond_to? :sqr2 }
|
32
38
|
|
33
39
|
it { respond_to? :foo }
|
34
40
|
it { respond_to? :bar }
|
@@ -37,17 +43,17 @@ describe Synchronisable::DSL::Macro do
|
|
37
43
|
its(:bar) { should eq(1) }
|
38
44
|
|
39
45
|
it 'not raises error' do
|
40
|
-
expect {
|
46
|
+
expect { HasMacroFooSubclass.carefull }.to_not raise_error
|
41
47
|
end
|
42
48
|
|
43
49
|
it 'equals to the new default value' do
|
44
|
-
expect(
|
50
|
+
expect(HasMacroFooSubclass.carefull).to eq(0)
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|
48
54
|
|
49
55
|
describe 'methods' do
|
50
|
-
subject {
|
56
|
+
subject { HasMacroFooSubclass }
|
51
57
|
|
52
58
|
it { respond_to? :sqr }
|
53
59
|
its(:sqr) { respond_to? :call }
|
@@ -56,4 +62,15 @@ describe Synchronisable::DSL::Macro do
|
|
56
62
|
expect(subject.sqr.(2)).to eq(4)
|
57
63
|
end
|
58
64
|
end
|
65
|
+
|
66
|
+
describe 'class attributes' do
|
67
|
+
subject { HasMacroBar }
|
68
|
+
|
69
|
+
it { should_not respond_to? :bar }
|
70
|
+
it { should_not respond_to? :foo }
|
71
|
+
it { should_not respond_to? :sqr }
|
72
|
+
|
73
|
+
it { respond_to? :baz }
|
74
|
+
it { respond_to? :sqr2 }
|
75
|
+
end
|
59
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synchronisable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasiliy Yorkin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -308,7 +308,6 @@ files:
|
|
308
308
|
- lib/synchronisable.rb
|
309
309
|
- lib/synchronisable/attribute_mapper.rb
|
310
310
|
- lib/synchronisable/context.rb
|
311
|
-
- lib/synchronisable/data_builder.rb
|
312
311
|
- lib/synchronisable/dsl/associations.rb
|
313
312
|
- lib/synchronisable/dsl/associations/association.rb
|
314
313
|
- lib/synchronisable/dsl/associations/has_many.rb
|
@@ -321,6 +320,7 @@ files:
|
|
321
320
|
- lib/synchronisable/exceptions.rb
|
322
321
|
- lib/synchronisable/gateway.rb
|
323
322
|
- lib/synchronisable/input_descriptor.rb
|
323
|
+
- lib/synchronisable/input_dispatcher.rb
|
324
324
|
- lib/synchronisable/locale/en.yml
|
325
325
|
- lib/synchronisable/locale/ru.yml
|
326
326
|
- lib/synchronisable/model.rb
|
@@ -417,8 +417,9 @@ files:
|
|
417
417
|
- spec/spec_helper.rb
|
418
418
|
- spec/synchronisable/dsl/macro_spec.rb
|
419
419
|
- spec/synchronisable/models/import_spec.rb
|
420
|
-
- spec/synchronisable/support/
|
421
|
-
- spec/synchronisable/support/
|
420
|
+
- spec/synchronisable/support/has_macro_bar.rb
|
421
|
+
- spec/synchronisable/support/has_macro_foo.rb
|
422
|
+
- spec/synchronisable/support/has_macro_foo_subclass.rb
|
422
423
|
- spec/synchronisable/support/shared/contexts.rb
|
423
424
|
- spec/synchronisable/support/shared/examples.rb
|
424
425
|
- spec/synchronisable/synchronisable_spec.rb
|
@@ -535,8 +536,9 @@ test_files:
|
|
535
536
|
- spec/spec_helper.rb
|
536
537
|
- spec/synchronisable/dsl/macro_spec.rb
|
537
538
|
- spec/synchronisable/models/import_spec.rb
|
538
|
-
- spec/synchronisable/support/
|
539
|
-
- spec/synchronisable/support/
|
539
|
+
- spec/synchronisable/support/has_macro_bar.rb
|
540
|
+
- spec/synchronisable/support/has_macro_foo.rb
|
541
|
+
- spec/synchronisable/support/has_macro_foo_subclass.rb
|
540
542
|
- spec/synchronisable/support/shared/contexts.rb
|
541
543
|
- spec/synchronisable/support/shared/examples.rb
|
542
544
|
- spec/synchronisable/synchronisable_spec.rb
|