Class: RuboCop::Cop::Rails::ApplicationRecord

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector, TargetRailsVersion
Includes:
EnforceSuperclass
Defined in:
lib/rubocop/cop/rails/application_record.rb

Overview

Checks that models subclass ‘ApplicationRecord` with Rails 5.0.

It is a common practice to define models inside migrations in order to retain forward compatibility by avoiding loading any application code. And so migration files are excluded by default for this cop.

Examples:


# good
class Rails5Model < ApplicationRecord
  # ...
end

# bad
class Rails4Model < ActiveRecord::Base
  # ...
end

Constant Summary collapse

MSG =
'Models should subclass `ApplicationRecord`.'
SUPERCLASS =
'ApplicationRecord'
BASE_PATTERN =
'(const (const {nil? cbase} :ActiveRecord) :Base)'

Constants included from TargetRailsVersion

TargetRailsVersion::TARGET_GEM_NAME, TargetRailsVersion::USES_REQUIRES_GEM_API

Method Summary

Methods included from TargetRailsVersion

minimum_target_rails_version, support_target_rails_version?

Methods included from EnforceSuperclass

included, #on_class, #on_send