2016-08-24 12:49:21 +05:30
|
|
|
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-12-21 20:55:43 +05:30
|
|
|
dirname(node).end_with?('db/migrate', 'db/geo/migrate') || in_post_deployment_migration?(node)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def in_post_deployment_migration?(node)
|
2019-12-21 20:55:43 +05:30
|
|
|
dirname(node).end_with?('db/post_migrate', 'db/geo/post_migrate')
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def dirname(node)
|
|
|
|
File.dirname(node.location.expression.source_buffer.name)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|