Sha256: aa93e6f5222a9bf9c3c173ac61c3edb60d9c7b6e374aede1eac9b7393b80e6df

Contents?: true

Size: 947 Bytes

Versions: 4

Compression:

Stored size: 947 Bytes

Contents

require 'yaml'

module RuboCop
  module RSpec
    # Builds a YAML config file from two config hashes
    class ConfigFormatter
      NAMESPACES = /^(#{Regexp.union('RSpec', 'Capybara', 'FactoryGirl')})/
      STYLE_GUIDE_BASE_URL = 'http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'.freeze

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

      def dump
        YAML.dump(unified_config).gsub(NAMESPACES, "\n\\1")
      end

      private

      def unified_config
        cops.each_with_object(config.dup) do |cop, unified|
          unified[cop] = config.fetch(cop)
            .merge(descriptions.fetch(cop))
            .merge('StyleGuide' => STYLE_GUIDE_BASE_URL + cop.sub('RSpec/', ''))
        end
      end

      def cops
        (descriptions.keys | config.keys).grep(NAMESPACES)
      end

      attr_reader :config, :descriptions
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-rspec-1.19.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.18.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.17.1 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.17.0 lib/rubocop/rspec/config_formatter.rb