2016-06-24 15:26:28 +00:00
|
|
|
module RuboCop
|
|
|
|
# Module containing helper methods for writing migration cops.
|
|
|
|
module MigrationHelpers
|
|
|
|
# Returns true if the given node originated from the db/migrate directory.
|
|
|
|
def in_migration?(node)
|
2019-09-19 00:06:11 +00:00
|
|
|
dirname(node).end_with?('db/migrate', 'db/geo/migrate') || in_post_deployment_migration?(node)
|
2016-06-24 15:26:28 +00:00
|
|
|
end
|
2017-12-11 16:34:51 +00:00
|
|
|
|
|
|
|
def in_post_deployment_migration?(node)
|
2019-09-19 00:06:11 +00:00
|
|
|
dirname(node).end_with?('db/post_migrate', 'db/geo/post_migrate')
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2017-12-11 16:34:51 +00:00
|
|
|
|
2019-09-19 00:06:11 +00:00
|
|
|
def dirname(node)
|
|
|
|
File.dirname(node.location.expression.source_buffer.name)
|
2017-12-11 16:34:51 +00:00
|
|
|
end
|
2016-06-24 15:26:28 +00:00
|
|
|
end
|
|
|
|
end
|