Class: RuboCop::Cop::Rails::ReflectionClassName

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rails/reflection_class_name.rb

Overview

This cop checks if the value of the option `class_name`, in the definition of a reflection is a string.

Examples:

# bad
has_many :accounts, class_name: Account
has_many :accounts, class_name: Account.name

# good
has_many :accounts, class_name: 'Account'

Constant Summary collapse

MSG =
'Use a string value for `class_name`.'
RESTRICT_ON_SEND =
%i[has_many has_one belongs_to].freeze
ALLOWED_REFLECTION_CLASS_TYPES =
%i[dstr str sym].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



35
36
37
38
39
# File 'lib/rubocop/cop/rails/reflection_class_name.rb', line 35

def on_send(node)
  association_with_reflection(node) do |reflection_class_name|
    add_offense(reflection_class_name.loc.expression)
  end
end