Class: Mutant::Config Private

Inherits:
Object
  • Object
show all
Includes:
Unparser::Adamantium
Defined in:
lib/mutant.rb,
lib/mutant/config.rb,
lib/mutant/config/coverage_criteria.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Standalone configuration of a mutant execution.

Does not reference any “external” volatile state. The configuration applied to current environment is being represented by the Mutant::Env object.

rubocop:disable Metrics/ClassLength

Defined Under Namespace

Classes: CoverageCriteria

Constant Summary collapse

DEFAULT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

new(
  coverage_criteria:     Config::CoverageCriteria::DEFAULT,
  expression_parser:     Expression::Parser.new(
    types: [
      Expression::Descendants,
      Expression::Method,
      Expression::Methods,
      Expression::Namespace::Exact,
      Expression::Namespace::Recursive
    ]
  ),
  environment_variables: EMPTY_HASH,
  fail_fast:             false,
  hooks:                 EMPTY_ARRAY,
  includes:              EMPTY_ARRAY,
  integration:           Integration::Config::DEFAULT,
  isolation:             Mutant::Isolation::Fork.new(world: WORLD),
  jobs:                  nil,
  matcher:               Matcher::Config::DEFAULT,
  mutation:              Mutation::Config::EMPTY,
  reporter:              Reporter::CLI.build(WORLD.stdout),
  requires:              EMPTY_ARRAY
)
MORE_THAN_ONE_CONFIG_FILE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

<<~'MESSAGE'
  Found more than one candidate for use as implicit config file: %s
MESSAGE
CANDIDATES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%w[
  .mutant.yml
  config/mutant.yml
  mutant.yml
].freeze
MUTATION_TIMEOUT_DEPRECATION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

<<~'MESSAGE'
  Deprecated configuration toplevel key `mutation_timeout` found.

  This key will be removed in the next major version.
  Instead place your mutation timeout configuration under the `mutation` key
  like this:

  ```
  # mutant.yml
  mutation:
    timeout: 10.0 # float here.
  ```
MESSAGE
INTEGRATION_DEPRECATION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

<<~'MESSAGE'
  Deprecated configuration toplevel string key `integration` found.

  This key will be removed in the next major version.
  Instead place your integration configuration under the `integration.name` key
  like this:

  ```
  # mutant.yml
  integration:
    name: your_integration # typically rspec or minitest
  ```
MESSAGE
PATHNAME_ARRAY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Transform::Array.new(
  transform: Transform::Sequence.new(
    steps: [
      Transform::STRING,
      Transform::Exception.new(error_class: ArgumentError, block: Pathname.public_method(:new))
    ]
  )
)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(cli_config:, world:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Load the configuration



97
98
99
100
101
102
103
104
# File 'lib/mutant/config.rb', line 97

def self.load(cli_config:, world:)
  load_config_file(reporter: cli_config.reporter, world: world).fmap do |file_config|
    DEFAULT.with(
      jobs:     Etc.nprocessors,
      mutation: Mutation::Config::DEFAULT
    ).merge(file_config.merge(cli_config))
  end
end

.parse_environment_variables(hash) ⇒ Either<String,Hash<String,String>]

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse a hash of environment variables

Parameters:

  • (Hash<Object,Object>)

Returns:

  • (Either<String,Hash<String,String>])

    Either<String,Hash<String,String>]



165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/mutant/config.rb', line 165

def self.parse_environment_variables(hash)
  invalid = hash.keys.reject { |key| key.instance_of?(String) }
  return Either::Left.new("Non string keys: #{invalid}") if invalid.any?

  invalid = hash.keys.grep_v(ENV_VARIABLE_KEY_REGEXP)
  return Either::Left.new("Invalid keys: #{invalid}") if invalid.any?

  invalid = hash.values.reject { |value| value.instance_of?(String) }
  return Either::Left.new("Non string values: #{invalid}") if invalid.any?

  Either::Right.new(hash)
end

Instance Method Details

#merge(other) ⇒ Config

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Merge with other config

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength

Parameters:

Returns:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mutant/config.rb', line 79

def merge(other)
  other.with(
    coverage_criteria:     coverage_criteria.merge(other.coverage_criteria),
    environment_variables: environment_variables.merge(other.environment_variables),
    fail_fast:             fail_fast || other.fail_fast,
    hooks:                 hooks + other.hooks,
    includes:              includes + other.includes,
    integration:           integration.merge(other.integration),
    jobs:                  other.jobs || jobs,
    matcher:               matcher.merge(other.matcher),
    mutation:              mutation.merge(other.mutation),
    requires:              requires + other.requires
  )
end