Welcome to mirror list, hosted at ThFree Co, Russian Federation.

polymorphic_associations.rb « cop « rubocop - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7d55470455073ed6d98ac56fb781b85675f50fe2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require_relative '../model_helpers'

module RuboCop
  module Cop
    # Cop that prevents the use of polymorphic associations
    class PolymorphicAssociations < RuboCop::Cop::Cop
      include ModelHelpers

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

      def on_send(node)
        return unless in_model?(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, :expression) if key_name == :polymorphic
        end
      end
    end
  end
end