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: d49b81e66a19302fc586225b0b9b53d307daacc5da01b876bdb882c2b2be3c8e
4
- data.tar.gz: 52aac6177166296c0500d2a60b9e7fba9c5ed5215a31db57feec17d6fe7b0937
3
+ metadata.gz: 9e9b338c0155871428c1d59ed10ef0a15f1c87a909b37f634eb63dfd9f442683
4
+ data.tar.gz: 71b95e1f2f73ee07aec4948540abf620ca33d162d6de8e5d4c1617442f3e9530
5
5
  SHA512:
6
- metadata.gz: 1776e46980f98dc20f4a68da11f0a24a540b41d63721425fc8c3d31a9985f86a98143862b822925ec3695a03ccd8de027b6e4b7ea0261732a74d8deba10bc096
7
- data.tar.gz: c7e121bb64826de63415dbbb5a385d3f85c2862dd20f5ed2678bfa7b02e63442c277faa68d1f3bc6d3babe2ad88b0626391748478647ea13bda47735a8034f5e
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
- return unless node.method_name == :validates
22
-
23
- uniqueness(node) do |option|
24
- add_offense(option)
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.arguments.last
35
+ options = node.last_argument
32
36
  return unless options.hash_type?
33
37
 
34
- options.each_child_node do |child|
35
- yield child if uniquness_validation?(child)
38
+ options.each_child_node(:pair) do |pair|
39
+ yield pair if uniquness_validation?(pair)
36
40
  end
37
41
  end
38
42
  end
@@ -1,3 +1,3 @@
1
1
  module DatabaseValidations
2
- VERSION = '0.8.1'.freeze
2
+ VERSION = '0.8.2'.freeze
3
3
  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.1
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-09 00:00:00.000000000 Z
11
+ date: 2019-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord