Class: Rubocop::Cop::PolymorphicAssociations

Inherits:
RuboCop::Cop::Base
  • Object
show all
Defined in:
lib/rubocop/cop/polymorphic_associations.rb

Overview

Cop that prevents the use of polymorphic associations

Constant Summary collapse

MSG =
'Do not use polymorphic associations, use separate tables instead'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/rubocop/cop/polymorphic_associations.rb', line 9

def on_send(node)
  return unless node.children[1] == :belongs_to

  node.children.last.each_node(:pair) do |pair|
    key_name = pair.children[0].children[0]

    add_offense(pair) if key_name == :polymorphic
  end
end