synced 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/synced.rb +9 -0
- data/lib/synced/synchronizer.rb +36 -21
- data/lib/synced/version.rb +1 -1
- metadata +27 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90439e42a4207f1d7fb304492d01dbda6ca3c519
|
4
|
+
data.tar.gz: df7f7f52f5ae49f7c8dd30178a6bb6ec07c4e723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0648b7cec0c209758e6992d59377beeee9a3fdb80157013025c2ba9af4155e4acad635f0e2e5ea11490ceb8db3723328347370c76502f6222caeed1877923e21
|
7
|
+
data.tar.gz: 9b9697a81e6056b27d402f8dd130af09f3c08c9f66babd7782843c3e661c53fc9a3abd397a964b50b2a2b2180171209a61a181f0a6d51c1c3323cb880fe5a651
|
data/lib/synced.rb
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
require "synced/rails"
|
2
2
|
|
3
3
|
module Synced
|
4
|
+
# Default instrumenter which does nothing.
|
5
|
+
module NoopInstrumenter
|
6
|
+
def self.instrument(name, payload = {})
|
7
|
+
yield payload if block_given?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
cattr_accessor :instrumenter
|
12
|
+
self.instrumenter = NoopInstrumenter
|
4
13
|
end
|
data/lib/synced/synchronizer.rb
CHANGED
@@ -55,25 +55,32 @@ module Synced
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def perform
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
remote.extend(@mapper) if @mapper
|
63
|
-
local_object = local_object_by_remote_id(remote.id) || relation_scope.new
|
64
|
-
local_object.attributes = default_attributes_mapping(remote)
|
65
|
-
local_object.attributes = local_attributes_mapping(remote)
|
66
|
-
local_object.save! if local_object.changed?
|
67
|
-
local_object.tap do |local_object|
|
68
|
-
@associations.each do |association|
|
69
|
-
klass = association.to_s.classify.constantize
|
70
|
-
klass.synchronize(remote: remote[association], scope: local_object,
|
71
|
-
remove: @remove)
|
72
|
-
end
|
58
|
+
instrument("perform.synced", model: @model_class) do
|
59
|
+
relation_scope.transaction do
|
60
|
+
instrument("remove_perform.synced", model: @model_class) do
|
61
|
+
remove_relation.send(remove_strategy) if @remove
|
73
62
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
63
|
+
instrument("sync_perform.synced", model: @model_class) do
|
64
|
+
remote_objects.map do |remote|
|
65
|
+
remote.extend(@mapper) if @mapper
|
66
|
+
local_object = local_object_by_remote_id(remote.id) || relation_scope.new
|
67
|
+
local_object.attributes = default_attributes_mapping(remote)
|
68
|
+
local_object.attributes = local_attributes_mapping(remote)
|
69
|
+
local_object.save! if local_object.changed?
|
70
|
+
local_object.tap do |local_object|
|
71
|
+
@associations.each do |association|
|
72
|
+
klass = association.to_s.classify.constantize
|
73
|
+
klass.synchronize(remote: remote[association], scope: local_object,
|
74
|
+
remove: @remove)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end.tap do |local_objects|
|
79
|
+
if updated_since_enabled? && @request_performed
|
80
|
+
instrument("update_synced_all_at_perform.synced", model: @model_class) do
|
81
|
+
relation_scope.update_all(@synced_all_at_key => Time.now)
|
82
|
+
end
|
83
|
+
end
|
77
84
|
end
|
78
85
|
end
|
79
86
|
end
|
@@ -145,8 +152,10 @@ module Synced
|
|
145
152
|
end
|
146
153
|
|
147
154
|
def fetch_remote_objects
|
148
|
-
|
149
|
-
|
155
|
+
instrument("fetch_remote_objects.synced", model: @model_class) do
|
156
|
+
api.paginate(resource_name, api_request_options).tap do
|
157
|
+
@request_performed = true
|
158
|
+
end
|
150
159
|
end
|
151
160
|
end
|
152
161
|
|
@@ -163,7 +172,9 @@ module Synced
|
|
163
172
|
end
|
164
173
|
|
165
174
|
def minimum_updated_at
|
166
|
-
|
175
|
+
instrument("minimum_updated_at.synced") do
|
176
|
+
relation_scope.minimum(@synced_all_at_key)
|
177
|
+
end
|
167
178
|
end
|
168
179
|
|
169
180
|
def updated_since_enabled?
|
@@ -194,6 +205,10 @@ module Synced
|
|
194
205
|
end
|
195
206
|
end
|
196
207
|
|
208
|
+
def instrument(*args, &block)
|
209
|
+
Synced.instrumenter.instrument(*args, &block)
|
210
|
+
end
|
211
|
+
|
197
212
|
class MissingAPIClient < StandardError
|
198
213
|
def initialize(scope, model_class)
|
199
214
|
@scope = scope
|
data/lib/synced/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synced
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastien Grosjean
|
@@ -15,126 +15,126 @@ dependencies:
|
|
15
15
|
name: rails
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 4.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 4.0.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: bookingsync-api
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: 0.0.20
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 0.0.20
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: hashie
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: sqlite3
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec-rails
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: guard-rspec
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- -
|
88
|
+
- - ">="
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: timecop
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- -
|
109
|
+
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: vcr
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- -
|
116
|
+
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- -
|
123
|
+
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: webmock
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
|
-
- -
|
130
|
+
- - ">="
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
|
-
- -
|
137
|
+
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
140
|
description: Keep your BookingSync Application synced with BookingSync.
|
@@ -144,16 +144,16 @@ executables: []
|
|
144
144
|
extensions: []
|
145
145
|
extra_rdoc_files: []
|
146
146
|
files:
|
147
|
+
- MIT-LICENSE
|
148
|
+
- README.md
|
149
|
+
- Rakefile
|
147
150
|
- config/routes.rb
|
151
|
+
- lib/synced.rb
|
148
152
|
- lib/synced/has_synced_data.rb
|
149
153
|
- lib/synced/model.rb
|
150
154
|
- lib/synced/rails.rb
|
151
155
|
- lib/synced/synchronizer.rb
|
152
156
|
- lib/synced/version.rb
|
153
|
-
- lib/synced.rb
|
154
|
-
- MIT-LICENSE
|
155
|
-
- Rakefile
|
156
|
-
- README.md
|
157
157
|
homepage: https://github.com/BookingSync/synced
|
158
158
|
licenses:
|
159
159
|
- MIT
|
@@ -164,18 +164,19 @@ require_paths:
|
|
164
164
|
- lib
|
165
165
|
required_ruby_version: !ruby/object:Gem::Requirement
|
166
166
|
requirements:
|
167
|
-
- -
|
167
|
+
- - ">="
|
168
168
|
- !ruby/object:Gem::Version
|
169
169
|
version: '0'
|
170
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
171
|
requirements:
|
172
|
-
- -
|
172
|
+
- - ">="
|
173
173
|
- !ruby/object:Gem::Version
|
174
174
|
version: '0'
|
175
175
|
requirements: []
|
176
176
|
rubyforge_project:
|
177
|
-
rubygems_version: 2.
|
177
|
+
rubygems_version: 2.2.2
|
178
178
|
signing_key:
|
179
179
|
specification_version: 4
|
180
180
|
summary: Keep your BookingSync Application synced with BookingSync.
|
181
181
|
test_files: []
|
182
|
+
has_rdoc:
|