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

Inherits:
RuboCop::Cop
  • 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: 
has_many :accounts, class_name: .name

# good
has_many :accounts, class_name: 'Account'

Constant Summary collapse

MSG =
'Use a string value for `class_name`.'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



29
30
31
32
33
# File 'lib/rubocop/cop/rails/reflection_class_name.rb', line 29

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