Module: RuboCop::Cop::MethodPreference

Included in:
Style::CollectionMethods, Style::StringMethods
Defined in:
lib/rubocop/cop/mixin/method_preference.rb

Overview

Common code for cops that deal with preferred methods.

Instance Method Summary collapse

Instance Method Details

#default_cop_configObject


23
24
25
# File 'lib/rubocop/cop/mixin/method_preference.rb', line 23

def default_cop_config
  ConfigLoader.default_configuration[cop_name]
end

#preferred_method(method) ⇒ Object


7
8
9
# File 'lib/rubocop/cop/mixin/method_preference.rb', line 7

def preferred_method(method)
  preferred_methods[method.to_sym]
end

#preferred_methodsObject


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rubocop/cop/mixin/method_preference.rb', line 11

def preferred_methods
  @preferred_methods ||=
    begin
      # Make sure default configuration 'foo' => 'bar' is removed from
      # the total configuration if there is a 'bar' => 'foo' override.
      default = default_cop_config['PreferredMethods']
      merged = cop_config['PreferredMethods']
      overrides = merged.values - default.values
      merged.reject { |key, _| overrides.include?(key) }.symbolize_keys
    end
end