class RuboCop::RSpec::ConfigFormatter
Builds a YAML config file from two config hashes
Constants
- COP_DOC_BASE_URL
- EXTENSION_ROOT_DEPARTMENT
Attributes
Public Class Methods
Source
# File lib/rubocop/rspec/config_formatter.rb, line 12 def initialize(config, descriptions) @config = config @descriptions = descriptions end
Public Instance Methods
Source
# File lib/rubocop/rspec/config_formatter.rb, line 17 def dump YAML.dump(unified_config) .gsub(%r{^\w+/}, "\n\\0") # Add an extra newline before each cop. .gsub(/^(\s+)- /, '\1 - ') # Add 2 spaces before each array element. .gsub('"~"', '~') # Don't quote tilde, YAML's null value. end
Private Instance Methods
Source
# File lib/rubocop/rspec/config_formatter.rb, line 34 def cops (descriptions.keys | config.keys).grep(EXTENSION_ROOT_DEPARTMENT) end
Source
# File lib/rubocop/rspec/config_formatter.rb, line 44 def reference(cop) COP_DOC_BASE_URL + cop end
Source
# File lib/rubocop/rspec/config_formatter.rb, line 38 def replace_nil(config) config.each do |key, value| config[key] = '~' if value.nil? end end
Source
# File lib/rubocop/rspec/config_formatter.rb, line 26 def unified_config cops.each_with_object(config.dup) do |cop, unified| replace_nil(unified[cop]) unified[cop].merge!(descriptions.fetch(cop)) unified[cop]['Reference'] = reference(cop) end end