validates_uniqueness_via_association 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 724284041847c2ef883b953724904d777fe7eb80
4
+ data.tar.gz: f00957e9ee30618e87088d673ada97a417c56943
5
+ SHA512:
6
+ metadata.gz: aa94676a2be71b180a2fe896c27576655ad1214af20cecc0d142e0938db21f86e72b38976533a67736abfbe82c1f48ac58cfbfe611afee674a4e28206e49dffc
7
+ data.tar.gz: 03e6d9bf2d97d7039e2a135312d2d8c165f9b209ed2d14d7a3d3a8cee0d4fb3427be1d8482f1c6a082b1ea07f454da808a9df311adcb85661d74b65e5c5ae1aa
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2013 Michael Grosser <michael@grosser.it>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ # there are 2 ways of failing a uniqueness validation:
3
+ # - change a single record
4
+ # - assign multiple new records with the same value
5
+ # validates :uniqueness only covers the first ... this covers both!
6
+
7
+ require "active_record"
8
+
9
+ module ValidatesUniquenessViaAssociation
10
+ def validates_uniqueness_via_association(attribute, association, message: :taken, associated: nil)
11
+ validate do
12
+ siblings = send(association).send(associated || self.class.name.underscore.pluralize) + [self]
13
+ siblings.uniq!
14
+ errors.add attribute, message if siblings.map(&attribute.to_sym).uniq!
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module ValidatesUniquenessViaAssociation
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: validates_uniqueness_via_association
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Grosser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 6.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 5.1.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 6.0.0
33
+ description:
34
+ email: michael@grosser.it
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - MIT-LICENSE
40
+ - lib/validates_uniqueness_via_association.rb
41
+ - lib/validates_uniqueness_via_association/version.rb
42
+ homepage: https://github.com/grosser/validates_uniqueness_via_association
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.2.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.5.1
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Validate uniqueness of multiple newly associated records
66
+ test_files: []