Class: CC::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/config.rb,
lib/cc/config/engine.rb,
lib/cc/config/prepare.rb,
lib/cc/config/engine_set.rb,
lib/cc/config/json_adapter.rb,
lib/cc/config/yaml_adapter.rb,
lib/cc/config/checks_adapter.rb,
lib/cc/config/default_adapter.rb,
lib/cc/config/validation/json.rb,
lib/cc/config/validation/yaml.rb,
lib/cc/config/validation/file_validator.rb,
lib/cc/config/validation/check_validator.rb,
lib/cc/config/validation/fetch_validator.rb,
lib/cc/config/validation/engine_validator.rb,
lib/cc/config/validation/hash_validations.rb,
lib/cc/config/validation/prepare_validator.rb

Direct Known Subclasses

JSONAdapter

Defined Under Namespace

Modules: Validation Classes: ChecksAdapter, DefaultAdapter, Engine, EngineSet, JSONAdapter, Prepare, YAMLAdapter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(analysis_paths: [], development: false, engines: [], exclude_patterns: [], prepare: Prepare.new) ⇒ Config

Returns a new instance of Config.



52
53
54
55
56
57
58
# File 'lib/cc/config.rb', line 52

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

Instance Attribute Details

#analysis_pathsObject (readonly)

Returns the value of attribute analysis_paths.



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

def analysis_paths
  @analysis_paths
end

#development=(value) ⇒ Object (writeonly)

Sets the attribute development

Parameters:

  • value

    the value to set the attribute development to.



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

def development=(value)
  @development = value
end

#enginesObject (readonly)

Returns the value of attribute engines.



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

def engines
  @engines
end

#exclude_patternsObject (readonly)

Returns the value of attribute exclude_patterns.



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

def exclude_patterns
  @exclude_patterns
end

#prepareObject (readonly)

Returns the value of attribute prepare.



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

def prepare
  @prepare
end

Class Method Details

.build(data) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/cc/config.rb', line 42

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

.loadObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cc/config.rb', line 28

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

Instance Method Details

#development?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/cc/config.rb', line 64

def development?
  @development
end

#disable_plugins!Object



68
69
70
# File 'lib/cc/config.rb', line 68

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

#merge(other) ⇒ Object



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

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