2016-06-24 11:26:28 -04: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-18 20:06:11 -04:00
|
|
|
dirname(node).end_with?('db/migrate', 'db/geo/migrate') || in_post_deployment_migration?(node)
|
2016-06-24 11:26:28 -04:00
|
|
|
end
|
2017-12-11 11:34:51 -05:00
|
|
|
|
|
|
|
def in_post_deployment_migration?(node)
|
2019-09-18 20:06:11 -04:00
|
|
|
dirname(node).end_with?('db/post_migrate', 'db/geo/post_migrate')
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2017-12-11 11:34:51 -05:00
|
|
|
|
2019-09-18 20:06:11 -04:00
|
|
|
def dirname(node)
|
|
|
|
File.dirname(node.location.expression.source_buffer.name)
|
2017-12-11 11:34:51 -05:00
|
|
|
end
|
2016-06-24 11:26:28 -04:00
|
|
|
end
|
|
|
|
end
|