validate_uniqueness_of_in_memory 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/validate_uniqueness_of_in_memory.rb +18 -14
- metadata +2 -2
@@ -1,17 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
hash
|
11
|
-
end
|
12
|
-
if collection.length > hashes.length
|
13
|
-
self.errors.add(:base, message)
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module ValidatesUniquenessOfInMemory
|
4
|
+
|
5
|
+
def validate_uniqueness_of_in_memory(collection, attrs, message)
|
6
|
+
hashes = self.send(collection).inject({}) do |hash, record|
|
7
|
+
key = attrs.map {|a| record.send(a).to_s }.join
|
8
|
+
if key.blank? || record.marked_for_destruction?
|
9
|
+
key = record.object_id
|
14
10
|
end
|
11
|
+
hash[key] = record unless hash[key]
|
12
|
+
hash
|
13
|
+
end
|
14
|
+
if collection.length > hashes.length
|
15
|
+
self.errors.add(:base, message)
|
15
16
|
end
|
16
17
|
end
|
17
|
-
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
ActiveRecord::Base.extend(ValidatesUniquenessOfInMemory)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validate_uniqueness_of_in_memory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-12-04 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description:
|
16
16
|
email: akiva.leeder@gmail.com
|