nested_attributes_uniqueness 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/nested_attributes_uniqueness/validator.rb +5 -2
- data/lib/nested_attributes_uniqueness/version.rb +1 -1
- 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: f071745f7be967c35d40b4d892fc9ae4a1de7426
|
4
|
+
data.tar.gz: 74cff35f978dbf9640041d90182be26cd056ee05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a40d64bda765a22ea4f423dea6cd5c5ad279e22008016e38c6553285baafb9844cb7ccd4fbd1d127900d37b7ad27809bf32e2d1b41e8cecb6f422c8a39dbfc98
|
7
|
+
data.tar.gz: 8c60f41a079de0c4d5ccbe3d52e0a29b950ad65b661e89d4d9a428b3deab5b96cfba3acb6b5c055f5fd0a7ba716e4040109a4ada0b2cf324b5a05e977f630777
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
NestedAttributesUniqueness
|
2
2
|
-------
|
3
3
|
|
4
|
-
This gem provides two class methods `validates_uniqueness_in_memory` and `validates_uniqueness_in_memory_for_tree_polymorphism` which
|
4
|
+
This gem provides two class methods `validates_uniqueness_in_memory` and `validates_uniqueness_in_memory_for_tree_polymorphism` which ensures that the nested attribute uniqueness validation is not only checked against DB records but also against the non-persisted objects in memory.
|
5
5
|
|
6
6
|
Installation
|
7
7
|
-------
|
@@ -79,6 +79,7 @@ module NestedAttributesUniqueness
|
|
79
79
|
collection.each do |record|
|
80
80
|
if (!record.marked_for_destruction? && record.errors.get(attribute).blank?)
|
81
81
|
attribute_value = record.send(attribute)
|
82
|
+
next if (options[:allow_blank] && attribute_value.blank?)
|
82
83
|
attribute_value = attribute_value.downcase if options[:case_sensitive] == false
|
83
84
|
key = [attribute_value]
|
84
85
|
key += Array.wrap(options[:scope]).map { |attribute| record.public_send(attribute) }
|
@@ -109,8 +110,10 @@ module NestedAttributesUniqueness
|
|
109
110
|
existing_records = record.class.where(query)
|
110
111
|
records_exists = existing_records.present?
|
111
112
|
if options[:scope]
|
112
|
-
|
113
|
-
|
113
|
+
Array.wrap(options[:scope]).each do |attribute|
|
114
|
+
scope_value = record.public_send(attribute)
|
115
|
+
existing_records = existing_records.where(:"#{ attribute }" => scope_value)
|
116
|
+
end
|
114
117
|
records_exists = existing_records.present?
|
115
118
|
end
|
116
119
|
records_exists
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nested_attributes_uniqueness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akshay
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-09-
|
13
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|