validate_uniqueness_of_in_memory 0.0.2 → 0.0.3

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.
@@ -1,17 +1,21 @@
1
- module ActiveRecord
2
- class Base
3
- def validate_uniqueness_of_in_memory(collection, attrs, message)
4
- hashes = collection.inject({}) do |hash, record|
5
- key = attrs.map {|a| record.send(a).to_s }.join
6
- if key.blank? || record.marked_for_destruction?
7
- key = record.object_id
8
- end
9
- hash[key] = record unless hash[key]
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
- end
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.2
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-11-18 00:00:00.000000000 Z
13
+ date: 2012-12-04 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description:
16
16
  email: akiva.leeder@gmail.com