Sha256: 355581d6b1ecff9c5c15d1afbf58d5252f6f6f9dcfcb8fbc17f47efae8cd41d7

Contents?: true

Size: 1.82 KB

Versions: 97

Compression:

Stored size: 1.82 KB

Contents

module CC
  class Config
    class YAMLAdapter
      DEFAULT_PATH = ".codeclimate.yml".freeze

      attr_reader :config

      def self.load(path = DEFAULT_PATH)
        new(::YAML.safe_load(File.read(path)))
      end

      def initialize(yaml = {})
        @config = yaml || {}

        upconvert_legacy_yaml!
      end

      private

      def coerce_engine(data)
        if [true, false].include?(data)
          { "enabled" => data }
        elsif data.is_a?(Hash)
          data
        else
          {}
        end
      end

      # Many of our plugins still expect:
      #
      #   { config: PATH }
      #
      # But we document, and hope to eventually move to:
      #
      #   { config: { file: PATH } }
      #
      # We need to munge from the latter to the former when/if we encounter it
      def convert_to_legacy_file_config(config)
        if config.is_a?(Hash) && config.keys.one? && config.key?("file")
          config["file"]
        else
          config
        end
      end

      def upconvert_legacy_yaml!
        config.delete("ratings")

        if config.key?("engines")
          config["plugins"] ||= config.delete("engines")
        end

        plugins = config.fetch("plugins", {})
        plugins.each do |engine, data|
          plugins[engine] = coerce_engine(data)
          if plugins.fetch(engine)["exclude_paths"]
            plugins.fetch(engine)["exclude_patterns"] ||= Array(plugins.fetch(engine).delete("exclude_paths"))
          end
          if plugins.fetch(engine)["config"]
            plugins.fetch(engine)["config"] = convert_to_legacy_file_config(
              plugins.fetch(engine).fetch("config"),
            )
          end
        end

        if config.key?("exclude_paths")
          config["exclude_patterns"] ||= Array(config.delete("exclude_paths"))
        end
      end
    end
  end
end

Version data entries

97 entries across 97 versions & 2 rubygems

Version Path
codeclimate-fede-0.85.38 lib/cc/config/yaml_adapter.rb
codeclimate-fede-0.85.37 lib/cc/config/yaml_adapter.rb
codeclimate-fede-0.85.36 lib/cc/config/yaml_adapter.rb
codeclimate-fede-0.85.35 lib/cc/config/yaml_adapter.rb
codeclimate-fede-0.85.33 lib/cc/config/yaml_adapter.rb
codeclimate-fede-0.85.32 lib/cc/config/yaml_adapter.rb
codeclimate-fede-0.85.31 lib/cc/config/yaml_adapter.rb
codeclimate-fede-0.85.30 lib/cc/config/yaml_adapter.rb
codeclimate-fede-0.85.21 lib/cc/config/yaml_adapter.rb
codeclimate-fede-0.85.24 lib/cc/config/yaml_adapter.rb
codeclimate-fede-0.85.23 lib/cc/config/yaml_adapter.rb
codeclimate-0.85.23 lib/cc/config/yaml_adapter.rb
codeclimate-0.85.22 lib/cc/config/yaml_adapter.rb
codeclimate-0.85.21 lib/cc/config/yaml_adapter.rb
codeclimate-0.85.19 lib/cc/config/yaml_adapter.rb
codeclimate-0.85.18 lib/cc/config/yaml_adapter.rb
codeclimate-0.85.17 lib/cc/config/yaml_adapter.rb
codeclimate-0.85.15 lib/cc/config/yaml_adapter.rb
codeclimate-0.85.14 lib/cc/config/yaml_adapter.rb
codeclimate-0.85.13 lib/cc/config/yaml_adapter.rb