BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
bbdaf982
Commit
bbdaf982
authored
Apr 24, 2017
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor the AddColumnWithDefault cop to use node matchers
parent
c3c465ac
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
9 deletions
+10
-9
add_column_with_default.rb
rubocop/cop/migration/add_column_with_default.rb
+10
-9
No files found.
rubocop/cop/migration/add_column_with_default.rb
View file @
bbdaf982
...
@@ -8,26 +8,27 @@ module RuboCop
...
@@ -8,26 +8,27 @@ module RuboCop
class
AddColumnWithDefault
<
RuboCop
::
Cop
::
Cop
class
AddColumnWithDefault
<
RuboCop
::
Cop
::
Cop
include
MigrationHelpers
include
MigrationHelpers
def_node_matcher
:add_column_with_default?
,
<<~
PATTERN
(send nil :add_column_with_default $...)
PATTERN
def_node_matcher
:defines_change?
,
<<~
PATTERN
(def :change ...)
PATTERN
MSG
=
'`add_column_with_default` is not reversible so you must manually define '
\
MSG
=
'`add_column_with_default` is not reversible so you must manually define '
\
'the `up` and `down` methods in your migration class, using `remove_column` in `down`'
.
freeze
'the `up` and `down` methods in your migration class, using `remove_column` in `down`'
.
freeze
def
on_send
(
node
)
def
on_send
(
node
)
return
unless
in_migration?
(
node
)
return
unless
in_migration?
(
node
)
return
unless
add_column_with_default?
(
node
)
name
=
node
.
children
[
1
]
return
unless
name
==
:add_column_with_default
node
.
each_ancestor
(
:def
)
do
|
def_node
|
node
.
each_ancestor
(
:def
)
do
|
def_node
|
next
unless
method_name
(
def_node
)
==
:change
next
unless
defines_change?
(
def_node
)
add_offense
(
def_node
,
:name
)
add_offense
(
def_node
,
:name
)
end
end
end
end
def
method_name
(
node
)
node
.
children
.
first
end
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment