acts_as_has_default 0.0.1 → 0.0.2
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: e4b432e5546e734a64e051bcac486ad4a4957af1
|
|
4
|
+
data.tar.gz: 52519fc9f5b5d1615b8401ff3da9063d179c204b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5288553ddb9aea6fe24e9c06f8f8d1d463a7459f5538d8e7b9c22a880259a9f337bd0f287177d67fe7f7838599c16da68787534ea561df25c80b6621bb5c68e2
|
|
7
|
+
data.tar.gz: abbe8d10a6999f422ee6a3654a16513df92e7f226647aafbae7cf07ad9b007d9484f0f4d4820ee7d6dba2f7400eae5b0738a4250a7b7b56f8b33d1f1360514af
|
|
@@ -14,7 +14,7 @@ module ActiveRecord
|
|
|
14
14
|
|
|
15
15
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
16
16
|
|
|
17
|
-
def
|
|
17
|
+
def defaults_scope_conditions_for_#{configuration[:column]}
|
|
18
18
|
scope = ::ActiveRecord::VERSION::MAJOR == 4 ? self.class.all : self.class.scoped
|
|
19
19
|
%w(#{configuration[:scope].join(' ')}).each do |attr|
|
|
20
20
|
scope = scope.where(attr.intern => self[attr.intern])
|
|
@@ -28,19 +28,19 @@ module ActiveRecord
|
|
|
28
28
|
|
|
29
29
|
def update_#{configuration[:column]}_as_default
|
|
30
30
|
unless #{configuration[:column]}
|
|
31
|
-
self.#{configuration[:column]} =
|
|
31
|
+
self.#{configuration[:column]} = defaults_scope_conditions_for_#{configuration[:column]}.where(self.class.arel_table[:id].not_eq(id)).empty?
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
true
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def invalidate_#{configuration[:column]}_as_default
|
|
38
|
-
|
|
38
|
+
defaults_scope_conditions_for_#{configuration[:column]}.where(self.class.arel_table[:id].not_eq(id)).update_all(['`#{configuration[:column]}` = ?', false]) if #{configuration[:column]}
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def elect_#{configuration[:column]}_as_default
|
|
42
|
-
unless
|
|
43
|
-
target =
|
|
42
|
+
unless defaults_scope_conditions_for_#{configuration[:column]}.where(self.class.arel_table[:id].not_eq(id)).empty?
|
|
43
|
+
target = defaults_scope_conditions_for_#{configuration[:column]}.where(self.class.arel_table[:id].not_eq(id)).first
|
|
44
44
|
target.update_attributes(#{configuration[:column]}: true) if target
|
|
45
45
|
end
|
|
46
46
|
end
|