class Coco::Configuration

Public: I know the configuration of coco. You can override the default configuration by putting a '.coco.yml' file in YAML format in the project root directory.

Examples

# Read the threshold value
config = Configuration.new
config[:threshold]
# => 100

# To override the threshold, put this line in '.coco.yml' file:
# :threshold: 70

Note you can set the threshold above 100% (to be sure to see all files) but you cannot set it under 0.

Constants

DEFAULT_OPTIONS

Public Class Methods

new() click to toggle source

Public: Initialize a Configuration.

# File lib/coco/configuration.rb, line 38
def initialize
  merge!(DEFAULT_OPTIONS)
  if File.exist?('.coco.yml')
    merge!(YAML.load_file('.coco.yml'))
  # Deprecated: Support of '.coco' file will be removed in v1.0.
  elsif File.exist?('.coco')
    warn(DeprecatedMessage.for_legacy_config_file)
    merge!(YAML.load_file('.coco'))
  end

  ensure_known_theme
  ensure_threeshold_compatibility
  ensure_directories_compatibility
  ensure_excludes_compatibility
  expand_directories
  remove_directories
end

Public Instance Methods

run_this_time?() click to toggle source

Public: Code coverage not have to run with every test/spec runs.

Here are the rules: If the configuration key :always_run is set to true, we always run the coverage. In case the configuration key :always_run is set to false, we have to check for an environment variable named 'COCO' to decide if we launch the coverage or not. When 'COCO' doesn't exist, or is the empty string, or '0', or 'false', we don't run coverage. When 'COCO' is set to any other value, we start coverage.

Returns true if coverage should start.

# File lib/coco/configuration.rb, line 68
def run_this_time?
  if self[:always_run]
    true
  else
    ![nil, '', '0', 'false'].include?(ENV['COCO'])
  end
end

Private Instance Methods

add_files(dir) click to toggle source
# File lib/coco/configuration.rb, line 84
def add_files(dir)
  Helpers.rb_files_from(dir).each { |file| self[:exclude] << file }
end
directories_present?() click to toggle source
# File lib/coco/configuration.rb, line 110
def directories_present?
  self[:directories]
end
ensure_directories_compatibility() click to toggle source
# File lib/coco/configuration.rb, line 103
def ensure_directories_compatibility
  if directories_present?
    warn(DeprecatedMessage.for_directories)
    self[:include] = self[:directories]
  end
end
ensure_excludes_compatibility() click to toggle source
# File lib/coco/configuration.rb, line 114
def ensure_excludes_compatibility
  if excludes_present?
    warn(DeprecatedMessage.for_excludes)
    self[:exclude] = self[:excludes]
  end
end
ensure_known_theme() click to toggle source
# File lib/coco/configuration.rb, line 125
def ensure_known_theme
  unless %w( light dark ).include?(self[:theme])
    warn("\n\nThe theme '#{self[:theme]}' didn't exist.\n\n")
    self[:theme] = 'light'
  end
end
ensure_threeshold_compatibility() click to toggle source
# File lib/coco/configuration.rb, line 92
def ensure_threeshold_compatibility
  if threeshold_present?
    warn(DeprecatedMessage.for_threeshold)
    self[:threshold] = self[:threeshold]
  end
end
excludes_present?() click to toggle source
# File lib/coco/configuration.rb, line 121
def excludes_present?
  self[:excludes]
end
expand_directories() click to toggle source
# File lib/coco/configuration.rb, line 78
def expand_directories
  self[:exclude].each do |file_or_dir|
    add_files file_or_dir if File.directory?(file_or_dir)
  end
end
remove_directories() click to toggle source
# File lib/coco/configuration.rb, line 88
def remove_directories
  self[:exclude].delete_if { |file_or_dir| File.directory?(file_or_dir) }
end
threeshold_present?() click to toggle source
# File lib/coco/configuration.rb, line 99
def threeshold_present?
  self[:threeshold]
end