Class: RuboCop::Cop::Code0::ZeroTrack::Migration::VersionedClass

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RuboCop::Code0::ZeroTrack::FileHelpers
Defined in:
lib/rubocop/cop/code0/zero_track/migration/versioned_class.rb

Constant Summary collapse

MIGRATION_CLASS =
'Code0::ZeroTrack::Database::Migration'
MSG_WRONG_BASE_CLASS =

rubocop:disable Layout/LineLength

"Don't use `%<base_class>s`. Use `#{MIGRATION_CLASS}` instead.".freeze
MSG_WRONG_VERSION =
"Don't use version `%<current_version>s` of `#{MIGRATION_CLASS}`. Use version `%<allowed_version>s` instead.".freeze

Instance Method Summary collapse

Methods included from RuboCop::Code0::ZeroTrack::FileHelpers

#basename, #dirname, #filepath, #in_migration?

Instance Method Details

#on_class(node) ⇒ Object

rubocop:enable Layout/LineLength



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rubocop/cop/code0/zero_track/migration/versioned_class.rb', line 21

def on_class(node)
  return unless in_migration?(node)

  return on_zerotrack_migration(node) if zerotrack_migration?(node)

  add_offense(
    node.parent_class,
    message: format(MSG_WRONG_BASE_CLASS, base_class: superclass(node))
  ) do |corrector|
    corrector.replace(node.parent_class, "#{MIGRATION_CLASS}[#{find_allowed_versions(node).last}]")
  end
end