Class: CC::Analyzer::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/analyzer/config.rb

Overview

TODO: replace each use of this with CC::Yaml and remove it

Instance Method Summary collapse

Constructor Details

#initialize(config_body) ⇒ Config

Returns a new instance of Config.



7
8
9
10
11
12
# File 'lib/cc/analyzer/config.rb', line 7

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

  expand_shorthand
end

Instance Method Details

#disable_engine(engine_name) ⇒ Object



49
50
51
52
53
# File 'lib/cc/analyzer/config.rb', line 49

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

#enable_engine(engine_name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/cc/analyzer/config.rb', line 34

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

#engine_config(engine_name) ⇒ Object



18
19
20
# File 'lib/cc/analyzer/config.rb', line 18

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

#engine_enabled?(engine_name) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/cc/analyzer/config.rb', line 30

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

#engine_namesObject



22
23
24
# File 'lib/cc/analyzer/config.rb', line 22

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

#engine_present?(engine_name) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/cc/analyzer/config.rb', line 26

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

#exclude_pathsObject



45
46
47
# File 'lib/cc/analyzer/config.rb', line 45

def exclude_paths
  @config["exclude_paths"]
end

#remove_engine(engine_name) ⇒ Object



55
56
57
58
59
# File 'lib/cc/analyzer/config.rb', line 55

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

#to_hashObject



14
15
16
# File 'lib/cc/analyzer/config.rb', line 14

def to_hash
  @config
end

#to_yamlObject



61
62
63
# File 'lib/cc/analyzer/config.rb', line 61

def to_yaml
  @config.to_yaml
end