ar_sync 1.0.0 → 1.0.1
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/Gemfile.lock +1 -1
- data/lib/ar_sync/class_methods.rb +7 -3
- data/lib/ar_sync/instance_methods.rb +37 -0
- data/lib/ar_sync/version.rb +1 -1
- data/src/graph/ArSyncStore.ts +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c79d18d97624ed5b34f6471838d6b96eb6cfb71bba00cee9344a370dbb309498
|
4
|
+
data.tar.gz: c967bed5ff59000fcc8c1de827e98f1b8caef20d71d67532d8203eff4d97724a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5966a10dfdce14e70e2df1a0d722889db8ff4bece153bf4d1bd73a8148dd6f79cb4581e254a26deed31c2fe09acbdcd9333cdbf6616ec8d892bfc0758ccd44e3
|
7
|
+
data.tar.gz: 87b53c9634f5afd4b4a1a708ce128d094290d3e5db9a24b70146dc4fc96091760efcdb5b8edf851f3ce83afb13f85e464e556d2c00890c4b36fa852871908d7a
|
data/Gemfile.lock
CHANGED
@@ -124,12 +124,12 @@ module ArSync::GraphSync::ClassMethods
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def sync_has_many(name, **option, &data_block)
|
127
|
-
_sync_children_info[name] = :many
|
127
|
+
_sync_children_info[name] = [:many, option, data_block]
|
128
128
|
_sync_has_many name, option, &data_block
|
129
129
|
end
|
130
130
|
|
131
131
|
def sync_has_one(name, **option, &data_block)
|
132
|
-
_sync_children_info[name] = :one
|
132
|
+
_sync_children_info[name] = [:one, option, data_block]
|
133
133
|
_sync_define name, option, &data_block
|
134
134
|
end
|
135
135
|
|
@@ -179,12 +179,13 @@ module ArSync::GraphSync::ClassMethods
|
|
179
179
|
def write_attribute(attr_name, value)
|
180
180
|
self.class.default_scoped.scoping do
|
181
181
|
@_sync_parents_info_before_mutation ||= _sync_current_parents_info
|
182
|
+
@_sync_belongs_to_info_before_mutation ||= _sync_current_belongs_to_info
|
182
183
|
end
|
183
184
|
super attr_name, value
|
184
185
|
end
|
185
186
|
end
|
186
187
|
prepend mod
|
187
|
-
attr_reader :_sync_parents_info_before_mutation
|
188
|
+
attr_reader :_sync_parents_info_before_mutation, :_sync_belongs_to_info_before_mutation
|
188
189
|
|
189
190
|
_sync_define :id
|
190
191
|
|
@@ -198,10 +199,12 @@ module ArSync::GraphSync::ClassMethods
|
|
198
199
|
|
199
200
|
before_destroy do
|
200
201
|
@_sync_parents_info_before_mutation ||= _sync_current_parents_info
|
202
|
+
@_sync_belongs_to_info_before_mutation ||= _sync_current_belongs_to_info
|
201
203
|
end
|
202
204
|
|
203
205
|
before_save on: :create do
|
204
206
|
@_sync_parents_info_before_mutation ||= _sync_current_parents_info
|
207
|
+
@_sync_belongs_to_info_before_mutation ||= _sync_current_belongs_to_info
|
205
208
|
end
|
206
209
|
|
207
210
|
%i[create update destroy].each do |action|
|
@@ -209,6 +212,7 @@ module ArSync::GraphSync::ClassMethods
|
|
209
212
|
next if ArSync.skip_notification?
|
210
213
|
self.class.default_scoped.scoping { _sync_notify action }
|
211
214
|
@_sync_parents_info_before_mutation = nil
|
215
|
+
@_sync_belongs_to_info_before_mutation = nil
|
212
216
|
end
|
213
217
|
end
|
214
218
|
end
|
@@ -82,6 +82,35 @@ module ArSync::GraphSync::InstanceMethods
|
|
82
82
|
parents
|
83
83
|
end
|
84
84
|
|
85
|
+
def _serializer_field_value(name)
|
86
|
+
field = self.class._serializer_field_info name
|
87
|
+
preloadeds = field.preloaders.map do |preloader|
|
88
|
+
args = [[self], nil, {}]
|
89
|
+
preloader.call(*(preloader.arity < 0 ? args : args.take(preloader.arity)))
|
90
|
+
end
|
91
|
+
instance_exec(*preloadeds, nil, {}, &field.data_block)
|
92
|
+
end
|
93
|
+
|
94
|
+
def _sync_current_belongs_to_info
|
95
|
+
belongs = {}
|
96
|
+
self.class._each_sync_child do |name, (type, option, data_block)|
|
97
|
+
next unless type == :one
|
98
|
+
option ||= {}
|
99
|
+
association_name = (option[:association] || name).to_s.underscore
|
100
|
+
association = self.class.reflect_on_association association_name
|
101
|
+
next if association && !association.belongs_to?
|
102
|
+
if association && !option[:preload] && !data_block
|
103
|
+
belongs[name] = {
|
104
|
+
type: association.foreign_type && self[association.foreign_type],
|
105
|
+
id: self[association.foreign_key]
|
106
|
+
}
|
107
|
+
else
|
108
|
+
belongs[name] = { value: _serializer_field_value(name) }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
belongs
|
112
|
+
end
|
113
|
+
|
85
114
|
def _sync_notify_parent(action)
|
86
115
|
if action == :create
|
87
116
|
parents = _sync_current_parents_info
|
@@ -125,6 +154,14 @@ module ArSync::GraphSync::InstanceMethods
|
|
125
154
|
end
|
126
155
|
|
127
156
|
def _sync_notify_self
|
157
|
+
belongs_was = _sync_belongs_to_info_before_mutation
|
158
|
+
belongs = _sync_current_belongs_to_info
|
159
|
+
belongs.each do |name, info|
|
160
|
+
next if belongs_was[name] == info
|
161
|
+
value = info.key?(:value) ? info[:value] : _serializer_field_value(name)
|
162
|
+
_sync_notify_child_added value, name, nil, true if value.is_a? ArSerializer::Serializable
|
163
|
+
_sync_notify_child_removed value, name, nil, true if value.nil?
|
164
|
+
end
|
128
165
|
ArSync.sync_graph_send(to: self, action: :update, model: self)
|
129
166
|
end
|
130
167
|
end
|
data/lib/ar_sync/version.rb
CHANGED
data/src/graph/ArSyncStore.ts
CHANGED
@@ -209,7 +209,7 @@ class ArSyncRecord extends ArSyncContainerBase {
|
|
209
209
|
collection.parentKey = aliasName
|
210
210
|
}
|
211
211
|
} else {
|
212
|
-
if (subQuery.attributes) this.paths.push(key);
|
212
|
+
if (subQuery.attributes && Object.keys(subQuery.attributes).length > 0) this.paths.push(key);
|
213
213
|
if (subData && subData.sync_keys) {
|
214
214
|
if (this.children[aliasName]) {
|
215
215
|
this.children[aliasName].replaceData(subData)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tompng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|