debian-mirror-gitlab/rubocop/migration_helpers.rb

24 lines
683 B
Ruby
Raw Normal View History

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
2020-04-08 14:13:33 +05:30
def version(node)
File.basename(node.location.expression.source_buffer.name).split('_').first.to_i
end
2019-12-21 20:55:43 +05:30
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