active_tools 0.0.27 → 0.0.28
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02a14a54d1213611e0c06354ee9484bb0acbc074
|
4
|
+
data.tar.gz: 5d8513542b8e45c4a9acdb0d9d9d16ff853888b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3824d5cf0f48488d110db5b033732dc4d64265f7301716d99cdd817560f73b91749f46e2d657270225466d8b7e7a955bb6bcbe3beb9cbd6531979e01a1e4e591
|
7
|
+
data.tar.gz: 34bf14f4bf1c4c67147c931841f89cc43b828d95019a6340d2b935640f70aafb4ec5c1068fb2dcf79cb7e131e887c90563ddb022f3d5ab0dffbaa6e761b26f02
|
@@ -4,7 +4,7 @@ module ActiveTools
|
|
4
4
|
class Adapter
|
5
5
|
attr_reader :owner, :assoc_name, :options
|
6
6
|
|
7
|
-
delegate :target, :
|
7
|
+
delegate :target, :reflection, :to => :association
|
8
8
|
|
9
9
|
def initialize(owner, assoc_name, options = {})
|
10
10
|
@owner = owner
|
@@ -39,7 +39,7 @@ module ActiveTools
|
|
39
39
|
store_backup!
|
40
40
|
create_template!
|
41
41
|
target.send("#{name}=", value)
|
42
|
-
if
|
42
|
+
if @backup.present? && same_records?(@backup, target, :attributes => @remote_attributes)
|
43
43
|
restore_backup!
|
44
44
|
end
|
45
45
|
end
|
@@ -87,7 +87,7 @@ module ActiveTools
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def try_commit_existed
|
90
|
-
if @template.present? && @uniq_by.any? && (existed = detect_existed)
|
90
|
+
if @template.present? && @uniq_by.any? && (existed = detect_existed) && !(@backup.present? && same_records?(@backup, existed, :attributes => @uniq_by))
|
91
91
|
warn "Adaptive fetching existed <#{existed.class.name}: #{existed.class.primary_key}: #{existed.send(existed.class.primary_key)}>"
|
92
92
|
self.target = existed
|
93
93
|
if updateable_backup?
|
@@ -133,6 +133,10 @@ module ActiveTools
|
|
133
133
|
end
|
134
134
|
|
135
135
|
private
|
136
|
+
|
137
|
+
def target_id
|
138
|
+
association.send(:target_id)
|
139
|
+
end
|
136
140
|
|
137
141
|
def detect_existed
|
138
142
|
outer_values = {}
|
@@ -198,9 +202,17 @@ module ActiveTools
|
|
198
202
|
@backup ||= target
|
199
203
|
end
|
200
204
|
end
|
201
|
-
|
202
|
-
def
|
203
|
-
|
205
|
+
|
206
|
+
def same_records?(*args)
|
207
|
+
options = args.extract_options!
|
208
|
+
attributes = options[:attributes]
|
209
|
+
result = true
|
210
|
+
prev_object = args.shift
|
211
|
+
args.each do |object|
|
212
|
+
result = result && eval(attributes.map {|a| "object.send(:#{a}) == prev_object.send(:#{a})"}.join(" && "))
|
213
|
+
prev_object = object
|
214
|
+
end
|
215
|
+
result
|
204
216
|
end
|
205
217
|
|
206
218
|
def valid_attribute?(name)
|
data/lib/active_tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Valery Kvon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|