database_validations 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e9b338c0155871428c1d59ed10ef0a15f1c87a909b37f634eb63dfd9f442683
|
4
|
+
data.tar.gz: 71b95e1f2f73ee07aec4948540abf620ca33d162d6de8e5d4c1617442f3e9530
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c29b334bf891fbe940d6e2f2873db03110708614aec60075453702be5c5aca0ac6ccde30d24c18d7530a49bc6646fbb3f417f94802f5ca5b7ff02ef51d7c8235
|
7
|
+
data.tar.gz: a635e8d67bf1135bd5325e34667407c87ef0dc360bff2e031fdc36bdd907ae41059dde31ebb6b46fd99a5346a840ae9191cc28507ed387df84ad7dc643cc16ba
|
@@ -7,32 +7,36 @@ module RuboCop
|
|
7
7
|
# # bad
|
8
8
|
# validates :slug, uniqueness: true
|
9
9
|
# validates :address, uniqueness: { scope: :user_id }
|
10
|
+
# validates_uniqueness_of :title
|
10
11
|
#
|
11
12
|
# # good
|
12
13
|
# validates_db_uniqueness_of :slug
|
13
14
|
# validates_db_uniqueness_of :address, scope: :user_id
|
15
|
+
# validates_db_uniqueness_of :title
|
14
16
|
#
|
15
17
|
class UniquenessOf < Cop
|
16
18
|
MSG = 'Use `validates_db_uniqueness_of`.'.freeze
|
17
19
|
|
18
|
-
def_node_matcher :uniquness_validation?, '(pair (sym :uniqueness)
|
20
|
+
def_node_matcher :uniquness_validation?, '(pair (sym :uniqueness) _)'
|
19
21
|
|
20
22
|
def on_send(node)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
if node.method_name == :validates_uniqueness_of
|
24
|
+
add_offense(node, location: :selector)
|
25
|
+
elsif node.method_name == :validates
|
26
|
+
uniqueness(node) do |option|
|
27
|
+
add_offense(option)
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
32
|
private
|
29
33
|
|
30
34
|
def uniqueness(node)
|
31
|
-
options = node.
|
35
|
+
options = node.last_argument
|
32
36
|
return unless options.hash_type?
|
33
37
|
|
34
|
-
options.each_child_node do |
|
35
|
-
yield
|
38
|
+
options.each_child_node(:pair) do |pair|
|
39
|
+
yield pair if uniquness_validation?(pair)
|
36
40
|
end
|
37
41
|
end
|
38
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Demin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|