Class: Evilution::Config

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

Constant Summary collapse

CONFIG_FILES =
%w[.evilution.yml config/evilution.yml].freeze
DEFAULTS =
{
  timeout: 30,
  format: :text,
  target: nil,
  min_score: 0.0,
  integration: :rspec,
  verbose: false,
  quiet: false,
  jobs: 1,
  fail_fast: nil,
  baseline: true,
  isolation: :auto,
  incremental: false,
  line_ranges: {},
  spec_files: []
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Config

Returns a new instance of Config.



30
31
32
33
34
35
# File 'lib/evilution/config.rb', line 30

def initialize(**options)
  file_options = options.delete(:skip_config_file) ? {} : load_config_file
  merged = DEFAULTS.merge(file_options).merge(options)
  assign_attributes(merged)
  freeze
end

Instance Attribute Details

#baselineObject (readonly)

Returns the value of attribute baseline.



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

def baseline
  @baseline
end

#fail_fastObject (readonly)

Returns the value of attribute fail_fast.



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

def fail_fast
  @fail_fast
end

#formatObject (readonly)

Returns the value of attribute format.



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

def format
  @format
end

#incrementalObject (readonly)

Returns the value of attribute incremental.



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

def incremental
  @incremental
end

#integrationObject (readonly)

Returns the value of attribute integration.



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

def integration
  @integration
end

#isolationObject (readonly)

Returns the value of attribute isolation.



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

def isolation
  @isolation
end

#jobsObject (readonly)

Returns the value of attribute jobs.



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

def jobs
  @jobs
end

#line_rangesObject (readonly)

Returns the value of attribute line_ranges.



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

def line_ranges
  @line_ranges
end

#min_scoreObject (readonly)

Returns the value of attribute min_score.



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

def min_score
  @min_score
end

#quietObject (readonly)

Returns the value of attribute quiet.



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

def quiet
  @quiet
end

#spec_filesObject (readonly)

Returns the value of attribute spec_files.



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

def spec_files
  @spec_files
end

#targetObject (readonly)

Returns the value of attribute target.



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

def target
  @target
end

#target_filesObject (readonly)

Returns the value of attribute target_files.



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

def target_files
  @target_files
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

#verboseObject (readonly)

Returns the value of attribute verbose.



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

def verbose
  @verbose
end

Class Method Details

.default_templateObject

Generates a default config file template.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/evilution/config.rb', line 85

def self.default_template
  <<~YAML
    # Evilution configuration
    # See: https://github.com/marinazzio/evilution

    # Per-mutation timeout in seconds (default: 30)
    # timeout: 30

    # Output format: text or json (default: text)
    # format: text

    # Minimum mutation score to pass (0.0 to 1.0, default: 0.0)
    # min_score: 0.0

    # Test integration: rspec (default: rspec)
    # integration: rspec

    # Number of parallel workers (default: 1)
    # jobs: 1

    # Stop after N surviving mutants (default: disabled)
    # fail_fast: 1
  YAML
end

.file_optionsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/evilution/config.rb', line 69

def self.file_options
  CONFIG_FILES.each do |path|
    next unless File.exist?(path)

    data = YAML.safe_load_file(path, symbolize_names: true)
    return data.is_a?(Hash) ? data : {}
  rescue Psych::SyntaxError, Psych::DisallowedClass => e
    raise ConfigError.new("failed to parse config file #{path}: #{e.message}", file: path)
  rescue SystemCallError => e
    raise ConfigError.new("cannot read config file #{path}: #{e.message}", file: path)
  end

  {}
end

Instance Method Details

#baseline?Boolean

Returns:

  • (Boolean)


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

def baseline?
  baseline
end

#fail_fast?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/evilution/config.rb', line 57

def fail_fast?
  !fail_fast.nil?
end

#html?Boolean

Returns:

  • (Boolean)


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

def html?
  format == :html
end

#incremental?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/evilution/config.rb', line 65

def incremental?
  incremental
end

#json?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/evilution/config.rb', line 37

def json?
  format == :json
end

#line_ranges?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/evilution/config.rb', line 49

def line_ranges?
  !line_ranges.empty?
end

#target?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/evilution/config.rb', line 53

def target?
  !target.nil?
end

#text?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/evilution/config.rb', line 41

def text?
  format == :text
end