class RuboCop::RSpec::ConfigFormatter

Builds a YAML config file from two config hashes

Constants

AMENDMENTS
COP_DOC_BASE_URL
EXTENSION_ROOT_DEPARTMENT
SUBDEPARTMENTS

Attributes

config[R]
descriptions[R]

Public Class Methods

new(config, descriptions) click to toggle source
# File lib/rubocop/rspec/config_formatter.rb, line 14
def initialize(config, descriptions)
  @config       = config
  @descriptions = descriptions
end

Public Instance Methods

dump() click to toggle source
# File lib/rubocop/rspec/config_formatter.rb, line 19
def dump
  YAML.dump(unified_config)
    .gsub(EXTENSION_ROOT_DEPARTMENT, "\n\\1")
    .gsub(*AMENDMENTS, "\n\\0")
    .gsub(/^(\s+)- /, '\1  - ')
    .gsub('"~"', '~')
end

Private Instance Methods

cops() click to toggle source
# File lib/rubocop/rspec/config_formatter.rb, line 39
def cops
  (descriptions.keys | config.keys).grep(EXTENSION_ROOT_DEPARTMENT)
end
reference(cop) click to toggle source
# File lib/rubocop/rspec/config_formatter.rb, line 49
def reference(cop)
  COP_DOC_BASE_URL + cop
end
replace_nil(config) click to toggle source
# File lib/rubocop/rspec/config_formatter.rb, line 43
def replace_nil(config)
  config.each do |key, value|
    config[key] = '~' if value.nil?
  end
end
unified_config() click to toggle source
# File lib/rubocop/rspec/config_formatter.rb, line 29
def unified_config
  cops.each_with_object(config.dup) do |cop, unified|
    next if SUBDEPARTMENTS.include?(cop) || AMENDMENTS.include?(cop)

    replace_nil(unified[cop])
    unified[cop].merge!(descriptions.fetch(cop))
    unified[cop]['Reference'] = reference(cop)
  end
end