Sha256: a9b86479fdf309454f9a7ae13795e3dc0c6eb58787577ace43bf288862ffdf0d

Contents?: true

Size: 1.81 KB

Versions: 77

Compression:

Stored size: 1.81 KB

Contents

require "cc/config/checks_adapter"
require "cc/config/default_adapter"
require "cc/config/engine"
require "cc/config/engine_set"
require "cc/config/json_adapter"
require "cc/config/prepare"
require "cc/config/validation/hash_validations"
require "cc/config/validation/check_validator"
require "cc/config/validation/engine_validator"
require "cc/config/validation/fetch_validator"
require "cc/config/validation/file_validator"
require "cc/config/validation/json"
require "cc/config/validation/prepare_validator"
require "cc/config/validation/yaml"
require "cc/config/yaml_adapter"

module CC
  class Config
    attr_reader \
      :analysis_paths,
      :engines,
      :exclude_patterns,
      :prepare

    attr_writer \
      :development

    def self.load
      config =
        if File.exist?(JSONAdapter::DEFAULT_PATH)
          JSONAdapter.load.config
        elsif File.exist?(YAMLAdapter::DEFAULT_PATH)
          YAMLAdapter.load.config
        else
          {}
        end
      config = DefaultAdapter.new(config).config
      config = ChecksAdapter.new(config).config
      build(config)
    end

    def self.build(data)
      new(
        engines: EngineSet.new(data.fetch("plugins", {})).engines,
        exclude_patterns: data.fetch("exclude_patterns", DefaultAdapter::EXCLUDE_PATTERNS),
        prepare: Prepare.from_data(data["prepare"]),
      )
    end

    def initialize(analysis_paths: [], development: false, engines: [], exclude_patterns: [], prepare: Prepare.new)
      @analysis_paths = analysis_paths
      @development = development
      @engines = engines
      @exclude_patterns = exclude_patterns
      @prepare = prepare
    end

    def merge(other)
      Merge.new(self, other).run
    end

    def development?
      @development
    end

    def disable_plugins!
      @engines.delete_if(&:plugin?)
    end
  end
end

Version data entries

77 entries across 77 versions & 2 rubygems

Version Path
codeclimate-0.85.12 lib/cc/config.rb
codeclimate-0.85.11 lib/cc/config.rb
codeclimate-0.85.10 lib/cc/config.rb
codeclimate-0.85.9 lib/cc/config.rb
codeclimate-0.85.8 lib/cc/config.rb
codeclimate-0.85.7 lib/cc/config.rb
codeclimate-0.85.6 lib/cc/config.rb
codeclimate-0.85.5 lib/cc/config.rb
codeclimate-0.85.4 lib/cc/config.rb
codeclimate-0.85.3 lib/cc/config.rb
codeclimate-0.85.2 lib/cc/config.rb
codeclimate-0.85.1 lib/cc/config.rb
codeclimate-0.85.0 lib/cc/config.rb
codeclimate-0.84.0 lib/cc/config.rb
codeclimate-0.83.0 lib/cc/config.rb
codeclimate-0.82.0 lib/cc/config.rb
codeclimate-0.81.0 lib/cc/config.rb
codeclimate-0.80.0 lib/cc/config.rb
codeclimate-0.79.0 lib/cc/config.rb
codeclimate-0.78.1 lib/cc/config.rb