Module: RuboCop::Cop::Rails::AllowedReceivers

Included in:
RedundantActiveRecordAllMethod
Defined in:
lib/rubocop/cop/rails/redundant_active_record_all_method.rb

Overview

TODO: In the future, please support only RuboCop 1.52+ and use RuboCop::Cop::AllowedReceivers: https://github.com/rubocop/rubocop/blob/v1.52.0/lib/rubocop/cop/mixin/allowed_receivers.rb At that time, this duplicated module implementation can be removed.

Instance Method Summary collapse

Instance Method Details

#allowed_receiver?(receiver) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
# File 'lib/rubocop/cop/rails/redundant_active_record_all_method.rb', line 10

def allowed_receiver?(receiver)
  receiver_name = receiver_name(receiver)

  allowed_receivers.include?(receiver_name)
end

#allowed_receiversObject



30
31
32
# File 'lib/rubocop/cop/rails/redundant_active_record_all_method.rb', line 30

def allowed_receivers
  cop_config.fetch('AllowedReceivers', [])
end

#receiver_name(receiver) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rubocop/cop/rails/redundant_active_record_all_method.rb', line 16

def receiver_name(receiver)
  return receiver_name(receiver.receiver) if receiver.receiver && !receiver.receiver.const_type?

  if receiver.send_type?
    if receiver.receiver
      "#{receiver_name(receiver.receiver)}.#{receiver.method_name}"
    else
      receiver.method_name.to_s
    end
  else
    receiver.source
  end
end