synchronisable 1.0.4 → 1.0.5
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/lib/synchronisable/controller.rb +1 -1
- data/lib/synchronisable/gateway.rb +1 -1
- data/lib/synchronisable/input_descriptor.rb +4 -0
- data/lib/synchronisable/input_parser.rb +11 -11
- data/lib/synchronisable/model/methods.rb +2 -3
- data/lib/synchronisable/synchronizer.rb +20 -10
- data/lib/synchronisable/version.rb +1 -1
- data/spec/dummy/app/gateways/gateway_base.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef3f05db3248f6b97f08228ce7efb74b4e515272
|
4
|
+
data.tar.gz: b973aef1b36c665a89cfcbb350863eea51034ba0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ef0a3f27605d49e471f170c889ac92a3895406765a770aa86ab907325c55077081cee6c0b12c809303dff7c2c3232ec0a90499c3e99ad8f966d58e09858c07c
|
7
|
+
data.tar.gz: 3c0ef536eb6433a0f421ea4d4f1f161aac67a2898e1314e13438857edaa4b9af12e394be6c222b8be465b75ba61d213bffe89bf04f4f146d9a67901532c42ba3
|
@@ -41,7 +41,7 @@ module Synchronisable
|
|
41
41
|
|
42
42
|
# Initiates model synchronization.
|
43
43
|
#
|
44
|
-
# @param data [Array<Hash>, Array<String>, Array<Integer>, String, Integer]
|
44
|
+
# @param data [Hash, Array<Hash>, Array<String>, Array<Integer>, String, Integer]
|
45
45
|
# synchronization data.
|
46
46
|
# If not specified, it will try to get array of hashes to sync with
|
47
47
|
# using defined gateway class or `fetch` lambda/proc
|
@@ -22,17 +22,17 @@ module Synchronisable
|
|
22
22
|
input = InputDescriptor.new(data)
|
23
23
|
|
24
24
|
result = case
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
when input.empty? || input.params?
|
26
|
+
@synchronizer.fetch(data || {})
|
27
|
+
when input.remote_id?
|
28
|
+
@synchronizer.find(data)
|
29
|
+
when input.local_id?
|
30
|
+
find_by_local_id(data)
|
31
|
+
when input.array_of_ids?
|
32
|
+
find_by_array_of_ids(input)
|
33
|
+
else
|
34
|
+
result = data.dup
|
35
|
+
end
|
36
36
|
|
37
37
|
[result].flatten.compact
|
38
38
|
end
|
@@ -11,16 +11,15 @@ module Synchronisable
|
|
11
11
|
# in your model synchronizer, than it will be used if no data supplied.
|
12
12
|
#
|
13
13
|
# @overload sync(data, options)
|
14
|
-
# @param data [Array<Hash>, Array<String>, Array<Integer>, String, Integer] synchronization data
|
14
|
+
# @param data [Hash, Array<Hash>, Array<String>, Array<Integer>, String, Integer] synchronization data
|
15
15
|
# @param options [Hash] synchronization options
|
16
|
-
# @option options [Hash] :
|
16
|
+
# @option options [Hash] :includes assocations to be synchronized.
|
17
17
|
# Use this option to override `has_one` & `has_many` assocations
|
18
18
|
# defined in model synchronizer.
|
19
19
|
# @overload sync(options)
|
20
20
|
# @overload sync(data)
|
21
21
|
# @overload sync
|
22
22
|
#
|
23
|
-
#
|
24
23
|
# @see Synchronisable::Controller
|
25
24
|
#
|
26
25
|
# @example Supplying array of hashes with remote attributes
|
@@ -44,17 +44,27 @@ module Synchronisable
|
|
44
44
|
attribute :gateway
|
45
45
|
|
46
46
|
# Lambda that returns array of hashes with remote attributes.
|
47
|
-
method :fetcher, default: -> { [] }
|
47
|
+
method :fetcher, default: -> (params = {}) { [] }
|
48
48
|
|
49
|
-
# Lambda that returns a hash with remote attributes by
|
49
|
+
# Lambda that returns a hash with remote attributes by params.
|
50
50
|
#
|
51
51
|
# @example Common use case
|
52
52
|
# class FooSynchronizer < Synchronisable::Synchronizer
|
53
|
-
#
|
53
|
+
# finder do |id|
|
54
54
|
# remote_source.find { |h| h[:foo_id] == id } }
|
55
55
|
# end
|
56
56
|
# end
|
57
|
-
|
57
|
+
# @example Composite identifier
|
58
|
+
# class BarSynchronizer < Synchronisable::Synchronizer
|
59
|
+
# finder do |params|
|
60
|
+
# remote_source.find do |h|
|
61
|
+
# h[:x] == params[:x] &&
|
62
|
+
# h[:y] == params[:y] &&
|
63
|
+
# h[:z] == params[:z]
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
# end
|
67
|
+
method :finder, default: -> (params) { nil }
|
58
68
|
|
59
69
|
# Lambda, that will be called before synchronization
|
60
70
|
# of each record and its assocations.
|
@@ -100,14 +110,14 @@ module Synchronisable
|
|
100
110
|
method :after_association_sync
|
101
111
|
|
102
112
|
class << self
|
103
|
-
def fetch
|
104
|
-
data = fetcher.()
|
105
|
-
data.present? ? data : gateway_instance.try(:fetch)
|
113
|
+
def fetch(params = {})
|
114
|
+
data = fetcher.(params)
|
115
|
+
data.present? ? data : gateway_instance.try(:fetch, params)
|
106
116
|
end
|
107
117
|
|
108
|
-
def find(
|
109
|
-
data = finder.(
|
110
|
-
data.present? ? data : gateway_instance.try(:find,
|
118
|
+
def find(params)
|
119
|
+
data = finder.(params)
|
120
|
+
data.present? ? data : gateway_instance.try(:find, params)
|
111
121
|
end
|
112
122
|
|
113
123
|
# Extracts remote id from given attribute hash.
|
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.0.
|
4
|
+
version: 1.0.5
|
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-07-
|
11
|
+
date: 2014-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|