Sha256: 6462b63303a179c97f5c3d044760e4f51c60dd33f040e54115b8d0ff63aa0f12

Contents?: true

Size: 1.65 KB

Versions: 22

Compression:

Stored size: 1.65 KB

Contents

require "yaml"

module CC
  module Analyzer
    class Config

      def initialize(config_body)
        @config = YAML.safe_load(config_body) || {"engines"=> {} }
        @config["engines"] ||= {}

        expand_shorthand
      end

      def to_hash
        @config
      end

      def engine_config(engine_name)
        @config["engines"][engine_name] || {}
      end

      def engine_names
        @config["engines"].keys.select { |name| engine_enabled?(name) }
      end

      def engine_present?(engine_name)
        @config["engines"][engine_name].present?
      end

      def engine_enabled?(engine_name)
        @config["engines"][engine_name] && @config["engines"][engine_name]["enabled"]
      end

      def enable_engine(engine_name)
        if engine_present?(engine_name)
          @config["engines"][engine_name]["enabled"] = true
        else
          @config["engines"][engine_name] = { "enabled" => true }
        end
      end

      def exclude_paths
        @config["exclude_paths"]
      end

      def disable_engine(engine_name)
        if engine_present?(engine_name) && engine_enabled?(engine_name)
          @config["engines"][engine_name]["enabled"] = false
        end
      end

      def remove_engine(engine_name)
        if engine_present?(engine_name)
          @config["engines"].delete(engine_name)
        end
      end

      def to_yaml
        @config.to_yaml
      end

    private

      def expand_shorthand
        @config["engines"].each do |name, engine_config|
          if [true, false].include?(engine_config)
            @config["engines"][name] = { "enabled" => engine_config }
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
codeclimate-0.1.4 lib/cc/analyzer/config.rb
codeclimate-0.1.3 lib/cc/analyzer/config.rb
codeclimate-0.1.2 lib/cc/analyzer/config.rb
codeclimate-0.1.0 lib/cc/analyzer/config.rb
codeclimate-0.0.25 lib/cc/analyzer/config.rb
codeclimate-0.0.24 lib/cc/analyzer/config.rb
codeclimate-0.0.23 lib/cc/analyzer/config.rb
codeclimate-0.0.22 lib/cc/analyzer/config.rb
codeclimate-0.0.21 lib/cc/analyzer/config.rb
codeclimate-0.0.18 lib/cc/analyzer/config.rb
codeclimate-0.0.17 lib/cc/analyzer/config.rb
codeclimate-0.0.16 lib/cc/analyzer/config.rb
codeclimate-0.0.15 lib/cc/analyzer/config.rb
codeclimate-0.0.14 lib/cc/analyzer/config.rb
codeclimate-0.0.13 lib/cc/analyzer/config.rb
codeclimate-0.0.11 lib/cc/analyzer/config.rb
codeclimate-0.0.10 lib/cc/analyzer/config.rb
codeclimate-0.0.9 lib/cc/analyzer/config.rb
codeclimate-0.0.7 lib/cc/analyzer/config.rb
codeclimate-0.0.6 lib/cc/analyzer/config.rb