module RuboCop::ExcludeLimit

Allows specified configuration options to have an exclude limit ie. a maximum value tracked that it can be used by `–auto-gen-config`.

Public Instance Methods

exclude_limit(parameter_name, method_name: transform(parameter_name)) click to toggle source

Sets up a configuration option to have an exclude limit tracked. The parameter name given is transformed into a method name (eg. `Max` becomes `self.max=` and `MinDigits` becomes `self.min_digits=`).

# File lib/rubocop/cop/exclude_limit.rb, line 10
def exclude_limit(parameter_name, method_name: transform(parameter_name))
  define_method("#{method_name}=") do |value|
    cfg = config_to_allow_offenses
    cfg[:exclude_limit] ||= {}
    current_max = cfg[:exclude_limit][parameter_name]
    value = [current_max, value].max if current_max
    cfg[:exclude_limit][parameter_name] = value
  end
end

Private Instance Methods

transform(parameter_name) click to toggle source
# File lib/rubocop/cop/exclude_limit.rb, line 22
def transform(parameter_name)
  parameter_name.gsub(/(?<!\A)(?=[A-Z])/, '_').downcase
end