synchronisable 1.1.9 → 1.2.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.
- checksums.yaml +4 -4
- data/.hound.yml +2 -0
- data/README.md +8 -0
- data/lib/generators/synchronisable/templates/initializer.rb +1 -1
- data/lib/synchronisable/dsl/association.rb +71 -0
- data/lib/synchronisable/dsl/associations.rb +4 -7
- data/lib/synchronisable/source.rb +2 -2
- data/lib/synchronisable/synchronizer.rb +2 -2
- data/lib/synchronisable/version.rb +2 -2
- data/lib/synchronisable/worker/associations.rb +1 -1
- metadata +5 -7
- data/lib/synchronisable/dsl/associations/association.rb +0 -72
- data/lib/synchronisable/dsl/associations/belongs_to.rb +0 -16
- data/lib/synchronisable/dsl/associations/has_many.rb +0 -16
- data/lib/synchronisable/dsl/associations/has_one.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9f2e26970dfe050c9902385f60c2dcbc7d54448
|
4
|
+
data.tar.gz: dd2ee445a9f95ea088cf7ec84136312cafc71c6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86838267edeb7919d1e379ce58e9a26620eb9da69757731d4e8d2b484d02cfc12984cf9ea65fcf373a499d6f52bc4d79a7b489c1bdaf4ab97560cc1017c64e7d
|
7
|
+
data.tar.gz: 2982a13a2ab1d01778cd4829f2666d261dc4f0b40da7f2dc97ce39aa21ce9cb77e913f2c8ed698347a354aa27945a87bc750ac19968c3ac818508c7f2051f32f
|
data/.hound.yml
ADDED
data/README.md
CHANGED
@@ -276,6 +276,14 @@ Post.sync
|
|
276
276
|
```
|
277
277
|
P.S.: Better readme & wiki is coming! ^__^
|
278
278
|
|
279
|
+
## Contributing
|
280
|
+
|
281
|
+
How to run tests:
|
282
|
+
```
|
283
|
+
cd spec/dummy
|
284
|
+
RAILS_ENV=test rake db:create db:migrate
|
285
|
+
```
|
286
|
+
|
279
287
|
## Support
|
280
288
|
|
281
289
|
<a href='https://www.codersclan.net/task/yorkinv' target='_blank'><img src='https://www.codersclan.net/button/yorkinv' alt='expert-button' width='205' height='64' style='width: 205px; height: 64px;'></a>
|
@@ -5,7 +5,7 @@ Synchronisable.configure do |config|
|
|
5
5
|
# `STDOUT` will be used for output.
|
6
6
|
#
|
7
7
|
# config.logging = {
|
8
|
-
# :logger => defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
8
|
+
# :logger => defined?(Rails) ? Rails.logger : Logger.new(STDOUT),
|
9
9
|
# :verbose => true,
|
10
10
|
# :colorize => true
|
11
11
|
# }
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'synchronisable/dsl/macro'
|
2
|
+
|
3
|
+
module Synchronisable
|
4
|
+
module DSL
|
5
|
+
# Association builder.
|
6
|
+
# Subclasses must implement #macro method.
|
7
|
+
class Association
|
8
|
+
include Synchronisable::DSL::Macro
|
9
|
+
|
10
|
+
KIND_KEY_SUFFIX_MAP = {
|
11
|
+
:belongs_to => :id,
|
12
|
+
:has_one => :id,
|
13
|
+
:has_many => :ids
|
14
|
+
}
|
15
|
+
|
16
|
+
class << self
|
17
|
+
attr_accessor :valid_options
|
18
|
+
|
19
|
+
def create(synchronizer, kind, name, options)
|
20
|
+
new(synchronizer, kind, name).create(options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
self.valid_options = %i(key class_name required force_sync)
|
25
|
+
|
26
|
+
attr_reader :kind, :name, :model, :key,
|
27
|
+
:required, :force_sync
|
28
|
+
|
29
|
+
def initialize(synchronizer, kind, name)
|
30
|
+
@synchronizer, @kind, @name = synchronizer, kind, name.to_sym
|
31
|
+
@key_suffix = KIND_KEY_SUFFIX_MAP[kind]
|
32
|
+
end
|
33
|
+
|
34
|
+
def create(options)
|
35
|
+
validate_options(options)
|
36
|
+
|
37
|
+
@key = options[:key]
|
38
|
+
@required = options[:required]
|
39
|
+
@force_sync = options[:force_sync]
|
40
|
+
|
41
|
+
if options[:class_name].present?
|
42
|
+
@model = options[:class_name].constantize
|
43
|
+
end
|
44
|
+
|
45
|
+
set_defaults
|
46
|
+
|
47
|
+
@synchronizer.associations[@key] = self
|
48
|
+
end
|
49
|
+
|
50
|
+
def model_name
|
51
|
+
@model.to_s.demodulize.underscore.to_sym
|
52
|
+
end
|
53
|
+
|
54
|
+
protected
|
55
|
+
|
56
|
+
def set_defaults
|
57
|
+
@required ||= false
|
58
|
+
@force_sync ||= false
|
59
|
+
|
60
|
+
@model ||= @name.to_s.classify.constantize
|
61
|
+
@key = "#{@name}_#{@key_suffix}" unless @key.present?
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def validate_options(options)
|
67
|
+
options.assert_valid_keys(Association.valid_options)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
require 'synchronisable/dsl/
|
2
|
-
require 'synchronisable/dsl/associations/has_many'
|
3
|
-
require 'synchronisable/dsl/associations/belongs_to'
|
1
|
+
require 'synchronisable/dsl/association'
|
4
2
|
|
5
3
|
module Synchronisable
|
6
4
|
module DSL
|
@@ -18,10 +16,9 @@ module Synchronisable
|
|
18
16
|
subclass.associations = {}
|
19
17
|
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
klass.create(self, name, options)
|
19
|
+
%i(has_one has_many belongs_to).each do |kind|
|
20
|
+
define_method(kind) do |name, options = {}|
|
21
|
+
Association.create(self, kind, name, options)
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
@@ -98,7 +98,7 @@ module Synchronisable
|
|
98
98
|
#
|
99
99
|
# @param source [Synchronisable::Source] synchronization source
|
100
100
|
# @param id association remote id
|
101
|
-
# @param association [Synchronisable::DSL::
|
101
|
+
# @param association [Synchronisable::DSL::Association]
|
102
102
|
# association builder
|
103
103
|
#
|
104
104
|
# @return [Boolean] `true` to continue sync, `false` to cancel
|
@@ -108,7 +108,7 @@ module Synchronisable
|
|
108
108
|
#
|
109
109
|
# @param source [Synchronisable::Source] synchronization source
|
110
110
|
# @param id association remote id
|
111
|
-
# @param association [Synchronisable::DSL::
|
111
|
+
# @param association [Synchronisable::DSL::Association]
|
112
112
|
# association builder
|
113
113
|
method :after_association_sync
|
114
114
|
|
@@ -10,7 +10,7 @@ module Synchronisable
|
|
10
10
|
#
|
11
11
|
# @see Synchronisable::Source
|
12
12
|
# @see Synchronisable::DSL::Associations
|
13
|
-
# @see Synchronisable::DSL::
|
13
|
+
# @see Synchronisable::DSL::Association
|
14
14
|
%w(child parent).each do |type|
|
15
15
|
define_method(:"sync_#{type}_associations") do
|
16
16
|
associations = @source.send(:"#{type}_associations")
|
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: 1.
|
4
|
+
version: 1.2.0
|
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-
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -286,6 +286,7 @@ extra_rdoc_files: []
|
|
286
286
|
files:
|
287
287
|
- ".coveralls.yml"
|
288
288
|
- ".gitignore"
|
289
|
+
- ".hound.yml"
|
289
290
|
- ".rspec"
|
290
291
|
- ".ruby-version"
|
291
292
|
- ".travis.yml"
|
@@ -305,11 +306,8 @@ files:
|
|
305
306
|
- lib/synchronisable/configuration.rb
|
306
307
|
- lib/synchronisable/context.rb
|
307
308
|
- lib/synchronisable/controller.rb
|
309
|
+
- lib/synchronisable/dsl/association.rb
|
308
310
|
- lib/synchronisable/dsl/associations.rb
|
309
|
-
- lib/synchronisable/dsl/associations/association.rb
|
310
|
-
- lib/synchronisable/dsl/associations/belongs_to.rb
|
311
|
-
- lib/synchronisable/dsl/associations/has_many.rb
|
312
|
-
- lib/synchronisable/dsl/associations/has_one.rb
|
313
311
|
- lib/synchronisable/dsl/macro.rb
|
314
312
|
- lib/synchronisable/dsl/macro/attribute.rb
|
315
313
|
- lib/synchronisable/dsl/macro/expression.rb
|
@@ -454,7 +452,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
454
452
|
version: '0'
|
455
453
|
requirements: []
|
456
454
|
rubyforge_project:
|
457
|
-
rubygems_version: 2.
|
455
|
+
rubygems_version: 2.4.2
|
458
456
|
signing_key:
|
459
457
|
specification_version: 4
|
460
458
|
summary: Provides base fuctionality (models, DSL) for AR synchronization with external
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'synchronisable/dsl/macro'
|
2
|
-
|
3
|
-
module Synchronisable
|
4
|
-
module DSL
|
5
|
-
module Associations
|
6
|
-
# Association builder.
|
7
|
-
# Subclasses must implement #macro method.
|
8
|
-
class Association
|
9
|
-
include Synchronisable::DSL::Macro
|
10
|
-
|
11
|
-
attribute :key_suffix, default: -> { raise NotImplementedError }
|
12
|
-
|
13
|
-
class << self
|
14
|
-
attr_accessor :valid_options
|
15
|
-
|
16
|
-
def create(synchronizer, name, options)
|
17
|
-
new(synchronizer, name).create(options)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
self.valid_options = %i(key class_name required force_sync)
|
22
|
-
|
23
|
-
attr_reader :name, :model, :key,
|
24
|
-
:required, :force_sync
|
25
|
-
|
26
|
-
def initialize(synchronizer, name)
|
27
|
-
@synchronizer, @name = synchronizer, name.to_sym
|
28
|
-
end
|
29
|
-
|
30
|
-
def create(options)
|
31
|
-
validate_options(options)
|
32
|
-
|
33
|
-
@key = options[:key]
|
34
|
-
@required = options[:required]
|
35
|
-
@force_sync = options[:force_sync]
|
36
|
-
|
37
|
-
if options[:class_name].present?
|
38
|
-
@model = options[:class_name].constantize
|
39
|
-
end
|
40
|
-
|
41
|
-
set_defaults
|
42
|
-
|
43
|
-
@synchronizer.associations[@key] = self
|
44
|
-
end
|
45
|
-
|
46
|
-
def macro
|
47
|
-
raise NotImplementedError
|
48
|
-
end
|
49
|
-
|
50
|
-
def model_name
|
51
|
-
@model.to_s.demodulize.underscore.to_sym
|
52
|
-
end
|
53
|
-
|
54
|
-
protected
|
55
|
-
|
56
|
-
def set_defaults
|
57
|
-
@required ||= false
|
58
|
-
@force_sync ||= false
|
59
|
-
|
60
|
-
@model ||= @name.to_s.classify.constantize
|
61
|
-
@key = "#{@name}_#{self.class.key_suffix}" unless @key.present?
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
def validate_options(options)
|
67
|
-
options.assert_valid_keys(Association.valid_options)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'synchronisable/dsl/associations/association'
|
2
|
-
|
3
|
-
module Synchronisable
|
4
|
-
module DSL
|
5
|
-
module Associations
|
6
|
-
# `belongs_to` association builder.
|
7
|
-
class BelongsTo < Association
|
8
|
-
key_suffix 'id'
|
9
|
-
|
10
|
-
def macro
|
11
|
-
:belongs_to
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'synchronisable/dsl/associations/association'
|
2
|
-
|
3
|
-
module Synchronisable
|
4
|
-
module DSL
|
5
|
-
module Associations
|
6
|
-
# `has_many` association builder.
|
7
|
-
class HasMany < Association
|
8
|
-
key_suffix 'ids'
|
9
|
-
|
10
|
-
def macro
|
11
|
-
:has_many
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'synchronisable/dsl/associations/association'
|
2
|
-
|
3
|
-
module Synchronisable
|
4
|
-
module DSL
|
5
|
-
module Associations
|
6
|
-
# `has_one` association builder.
|
7
|
-
class HasOne < Association
|
8
|
-
key_suffix 'id'
|
9
|
-
|
10
|
-
def macro
|
11
|
-
:has_one
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|