defaulter 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/defaulter/has_default.rb +24 -13
- data/lib/defaulter/version.rb +1 -1
- metadata +1 -1
@@ -10,8 +10,6 @@ module Defaulter
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def default=(record)
|
13
|
-
owner = proxy_association.owner
|
14
|
-
reflection = proxy_association.reflection
|
15
13
|
records = load
|
16
14
|
|
17
15
|
if records.include?(record)
|
@@ -26,20 +24,33 @@ module Defaulter
|
|
26
24
|
end
|
27
25
|
|
28
26
|
def << (models)
|
29
|
-
|
30
|
-
reflection = proxy_association.reflection
|
31
|
-
primes = models.select { |m| m.prime? }
|
27
|
+
primes = nil
|
32
28
|
|
33
|
-
models.
|
34
|
-
|
29
|
+
case models.class.name
|
30
|
+
when 'Array'
|
31
|
+
puts 'cowabunga'
|
32
|
+
models.first.prime = true if self.load.empty? && primes.empty? && !models.blank?
|
33
|
+
primes = models.select { |m| m.prime? }
|
34
|
+
model = models.delete(primes.last)
|
35
35
|
|
36
|
-
if model.blank?
|
37
|
-
self.concat(models)
|
38
|
-
else
|
39
|
-
models.each { |m| m.prime = false }
|
40
36
|
ActiveRecord::Base.transaction do
|
41
|
-
|
42
|
-
|
37
|
+
if model.blank?
|
38
|
+
self.concat(models) unless models.blank?
|
39
|
+
else
|
40
|
+
models.each { |m| m.prime = false }
|
41
|
+
self.where(prime: true).each { |r| r.update_attribute(:prime, false) }
|
42
|
+
self.concat(models + [model])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
else
|
46
|
+
unless models.blank?
|
47
|
+
loaded = !load.empty?
|
48
|
+
models.prime = true unless loaded
|
49
|
+
|
50
|
+
ActiveRecord::Base.transaction do
|
51
|
+
self.where(prime: true).each { |r| r.update_attribute(:prime, false) } if loaded && models.prime?
|
52
|
+
self.concat(models)
|
53
|
+
end
|
43
54
|
end
|
44
55
|
end
|
45
56
|
end
|
data/lib/defaulter/version.rb
CHANGED