rubocop-safe_migrations 0.0.1 → 0.0.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: cec0e19c9356d158c3d985bbd65357b20280cfea76ab528999d8d8d9dab86cbb
4
- data.tar.gz: b3dd6120ee8c4a422a71625d5c51fe23f0c409e1f896283a25c2438d69c6c82f
3
+ metadata.gz: 3649ce5cf29e895eb9639963ee1e26d5a57deed878c2dce600699b03c8a4dc62
4
+ data.tar.gz: 046e3c506c93b0ec04bde54d0a3ec8fa3f190d92678ab68a8e2b931ba717158b
5
5
  SHA512:
6
- metadata.gz: 9fbe586c0ed1ef2ae7dda2a203e562c7bdf7b1b8ed722ec6042fca1a157ad4a471c72c49960bde00657f290a54f665789284ebc2ff7ea786b6529280e2cbd065
7
- data.tar.gz: 90f43e4939f8bb3cc08b8649d1edab65da0378d731a5a58908b838b91b6f28dc5fc402c5f24e23e2fcb455e4a520ebe66fd5601f221da0831063ddc4a030623b
6
+ metadata.gz: 1cf46dd12f6d67b50f83edcab3f49f8f84d5c2ede5612a7ffb31cd9ca8670f346052da4ac66bb38f065fa3f2e0d42908c05482ae6d06189d9358d493d7576d90
7
+ data.tar.gz: 626594af95804cc4e22f0303b0b1bb984be3e5d0cf50f22ac41d8b88c5f8d65f3b8e0f5e96b4b3efca8f526b0f52fac25c63e615eb66495001a57c28b3d4804f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-safe_migrations (0.0.1)
4
+ rubocop-safe_migrations (0.0.2)
5
5
  rubocop
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -32,6 +32,16 @@ This is more importante to be avoided if you have your deploy pipeline configure
32
32
 
33
33
  By default, all active record methods that generate update, create or delete queries are checked by the cop, and if used on migrations an offense will be generated.
34
34
 
35
+ To turn some method available to be used on migration, just add it to AllowedMethods config on rubocop.yml, for example:
36
+
37
+ ```yaml
38
+ Migration/UpdatingDataInMigration:
39
+ AllowedMethods:
40
+ - toggle
41
+ ```
42
+
43
+ Using the configuration above, the cop will not add an offense when toggle method is used on migrations.
44
+
35
45
  ## Development
36
46
 
37
47
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -55,13 +65,13 @@ Everyone interacting in the Rubocop::SafeMigrations project's codebases, issue t
55
65
 
56
66
  ### For Updating data in migration rule
57
67
  - [ ] Adds check to active record update_counters method called on migration
68
+ - [ ] Adds check to active record create method called on migration
58
69
  - [ ] Adds check to active record create_or_update method called on migration
59
70
  - [ ] Adds check to active record decrement method called on migration
60
71
  - [ ] Adds check to active record increment method called on migration
61
72
  - [ ] Adds check to active record find_or_create method called on migration
62
73
  - [ ] Adds check to string sql execution with updates, inserts or deletions
63
74
  - [ ] Position offense message on the method being called, not in the end of line
64
- - [ ] Adds option to be able to whitelist some methods
65
75
  - [ ] Adds option to be able to add custom methods to blacklist
66
76
 
67
77
  ### For new rules
@@ -3,14 +3,20 @@ module RuboCop
3
3
  module Cop
4
4
  module Migration
5
5
  class UpdatingDataInMigration < RuboCop::Cop::Cop
6
- MSG = 'Updating or manipulating data in migration is unsafe!'.freeze
6
+ MSG = "Updating or manipulating data in migration is unsafe!".freeze
7
7
 
8
8
  def on_send(node)
9
+ return if allowed_methods.include?(node.method_name.to_s)
10
+
9
11
  add_offense(node) if forbidden_methods.include?(node.method_name)
10
12
  end
11
13
 
12
14
  private
13
15
 
16
+ def allowed_methods
17
+ cop_config["AllowedMethods"] || []
18
+ end
19
+
14
20
  def forbidden_methods
15
21
  %i[
16
22
  update
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module SafeMigrations
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-safe_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joao Paulo Lethier