Class: RuboCop::Cop::Rails::ModelAssociationSorting

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

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

MSG =
'Sort associations of the same type alphabetically. Expected order: %<expected>s.'
ASSOCIATION_METHODS =
[
  :belongs_to,
  :has_one,
  :has_many,
  :has_and_belongs_to_many
].freeze

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/rubocop/cop/rails/model_association_sorting.rb', line 15

def on_class(node)
  return unless model_class?(node)

  associations = find_associations(node)
  return if associations.size < 2

  check_association_sorting(associations)
end