aquasync_model 0.1.2 → 0.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/lib/models/concerns/aquasync_aggregated_methods.rb +34 -9
- 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: 5b19f1195106fe8588b7022f7a59d632894f0aa4
|
4
|
+
data.tar.gz: 3510b14f212a9f15a9f62fc7b5a72a64273671d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 176ebc703f6098f16b4d4e6f8f7fa40fc54b5078b16ab40ae3ac6412f8564f6c72c81c66ad80f181999816e30774c7a3e177730835dc3e61e7a075dd1874c7fb
|
7
|
+
data.tar.gz: f2b6bfaceb3ae5b4052f7271a9ddbe4915f61f06bc1a2fbb1987ee8e1c235d60e02e37f6e754a4e6043f95d8bd683b6befbee57a05553d68c4d0ee346629d5f5
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/concern'
|
2
|
+
require 'active_support/inflector'
|
2
3
|
|
3
4
|
module Aquasync
|
4
5
|
# Has a responsibility to implement Aquasync::DeltasAggregator requirement.
|
@@ -18,30 +19,54 @@ module Aquasync
|
|
18
19
|
module ClassMethods
|
19
20
|
# DeltasAggregator requirement
|
20
21
|
# @return [Array<Aquasync::Base>]
|
21
|
-
def aq_deltas(ust)
|
22
|
-
where(:ust.gt => ust)
|
22
|
+
def aq_deltas(ust, opts = {})
|
23
|
+
begin_of_association_chain(opts).where(:ust.gt => ust)
|
23
24
|
end
|
24
25
|
|
25
26
|
# DeltasAggregator requirement
|
26
27
|
# @return [NilClass]
|
27
|
-
def aq_commit_deltas(deltas)
|
28
|
-
deltas.each {|
|
28
|
+
def aq_commit_deltas(deltas, opts = {})
|
29
|
+
deltas.each {|d|
|
30
|
+
delta = append_attributes(d, opts)
|
31
|
+
commit_delta(delta, opts)
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
# Handle :append_attributes option.
|
36
|
+
# @param [Hash]
|
37
|
+
def append_attributes(delta, opts)
|
38
|
+
return delta unless opts[:append_attributes]
|
39
|
+
atr = opts[:append_attributes]
|
40
|
+
klass = self.name
|
41
|
+
delta.merge!(atr[:all]) if atr[:all]
|
42
|
+
delta.merge!(atr[klass]) if atr[klass]
|
43
|
+
delta
|
29
44
|
end
|
30
45
|
|
31
46
|
# commits a delta.
|
32
47
|
# @param [Hash]
|
33
|
-
def commit_delta(delta)
|
34
|
-
record = find_by(gid: delta["gid"])
|
48
|
+
def commit_delta(delta, opts)
|
49
|
+
record = begin_of_association_chain(opts).find_by(gid: delta["gid"])
|
35
50
|
if record
|
36
51
|
record.resolve_conflict(delta)
|
37
52
|
else
|
38
|
-
create_record_from_delta(delta)
|
53
|
+
create_record_from_delta(delta, opts)
|
39
54
|
end
|
40
55
|
end
|
41
56
|
|
42
57
|
# @param [Hash]
|
43
|
-
def create_record_from_delta(delta)
|
44
|
-
create!(delta)
|
58
|
+
def create_record_from_delta(delta, opts)
|
59
|
+
begin_of_association_chain(opts).create!(delta)
|
60
|
+
end
|
61
|
+
|
62
|
+
def begin_of_association_chain(opts)
|
63
|
+
model = opts[:begin_of_association_chain]
|
64
|
+
if(model)
|
65
|
+
# current_user Book => current_user.books
|
66
|
+
model.send(self.name.downcase.pluralize)
|
67
|
+
else
|
68
|
+
self
|
69
|
+
end
|
45
70
|
end
|
46
71
|
end
|
47
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aquasync_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaiinui
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|