defaulter 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- owner = proxy_association.owner
30
- reflection = proxy_association.reflection
31
- primes = models.select { |m| m.prime? }
27
+ primes = nil
32
28
 
33
- models.first.prime = true if self.load.empty? && primes.empty? && !models.blank?
34
- model = models.delete(primes.last)
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
- self.where(prime: true).each { |r| r.update_attribute(:prime, false) }
42
- self.concat(models + [model])
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
@@ -1,3 +1,3 @@
1
1
  module Defaulter
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defaulter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: