Sha256: 2b94aaef9313f43ba801ae9af7d0f84d115d720ab5b1bc9a6b897ec825fcf51e

Contents?: true

Size: 735 Bytes

Versions: 11

Compression:

Stored size: 735 Bytes

Contents

require 'yaml'

module RuboCop
  module RSpec
    # Builds a YAML config file from two config hashes
    class ConfigFormatter
      NAMESPACE = 'RSpec'.freeze

      def initialize(config, descriptions)
        @config       = config
        @descriptions = descriptions
      end

      def dump
        YAML.dump(unified_config).gsub(/^#{NAMESPACE}/, "\n#{NAMESPACE}")
      end

      private

      def unified_config
        cops.each_with_object(config.dup) do |cop, unified|
          unified[cop] = config.fetch(cop).merge(descriptions.fetch(cop))
        end
      end

      def cops
        (descriptions.keys + config.keys).uniq.grep(/\A#{NAMESPACE}/)
      end

      attr_reader :config, :descriptions
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rubocop-rspec-1.15.1 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.15.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.14.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.13.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.12.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.11.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.10.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.9.1 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.9.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.8.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.7.0 lib/rubocop/rspec/config_formatter.rb