Class: Mutineer::MutatorRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/mutineer/mutator_registry.rb

Overview

Maps operator names to operator classes.

DEFAULT_NAMES is the v1 default set (Tier-1 plus statement-removal). The Tier-2 operators live in ALL but are OFF by default — they only run when named via --operators or operators: in .mutineer.yml. Keeping DEFAULT_NAMES an explicit subset (not ALL.keys) is what keeps the default survivor set unchanged.

Constant Summary collapse

ALL =

All available mutator classes keyed by operator name.

{
  "arithmetic"         => Mutators::Arithmetic,
  "comparison"         => Mutators::Comparison,
  "boolean_connector"  => Mutators::BooleanConnector,
  "boolean_literal"    => Mutators::BooleanLiteral,
  "statement_removal"  => Mutators::StatementRemoval,
  "return_nil"         => Mutators::ReturnNil,
  "literal_mutation"   => Mutators::LiteralMutation,
  "condition_negation" => Mutators::ConditionNegation,
  "string_literal"     => Mutators::StringLiteral,
  "regex"              => Mutators::RegexLiteral,
  "collection_method"  => Mutators::CollectionMethod,
  "safe_navigation"    => Mutators::SafeNavigation,
  "range"              => Mutators::RangeLiteral,
  "negation_removal"   => Mutators::NegationRemoval,
  "chain_link"         => Mutators::ChainLink,
  "operand_removal"    => Mutators::OperandRemoval,
  "array_literal"      => Mutators::ArrayLiteral,
  "condition_true"     => Mutators::ConditionTrue,
  "condition_false"    => Mutators::ConditionFalse,
  "operator_assignment" => Mutators::OperatorAssignment
}.freeze
DEFAULT_NAMES =

The default Tier-1 operator set.

%w[arithmetic comparison boolean_connector boolean_literal statement_removal].freeze
TIER2_NAMES =

Tier-2 operators that remain opt-in.

%w[return_nil literal_mutation condition_negation string_literal regex collection_method
safe_navigation range negation_removal
chain_link operand_removal array_literal
condition_true condition_false operator_assignment].freeze
DESCRIPTIONS =

Short human-readable descriptions for each operator.

{
  "arithmetic"         => "+ <-> -, * <-> /, % -> *, ** -> *",
  "comparison"         => "< <-> <=, > <-> >=, == <-> !=",
  "boolean_connector"  => "&& <-> ||",
  "boolean_literal"    => "true <-> false, nil -> true",
  "statement_removal"  => "replace a non-final statement with nil",
  "return_nil"         => "replace a return / final expression with nil",
  "literal_mutation"   => "integer -> 0, 1, n+1; string -> empty",
  "condition_negation" => "wrap if/unless/ternary condition in !( ... )",
  "string_literal"     => "non-empty string -> \"\", empty string -> \"mutineer\"",
  "regex"              => "drop leading ^ / trailing $, swap + <-> *",
  "collection_method"  => "map<->each, all?<->any?, first<->last, min<->max, select<->reject",
  "safe_navigation"    => "&. -> .",
  "range"              => ".. <-> ...",
  "negation_removal"   => "!x, not x -> x",
  "chain_link"         => "drop one call from a chain: a.b.c -> a.c",
  "operand_removal"    => "a && b -> a, b",
  "array_literal"      => "[a, b] -> []",
  "condition_true"     => "if/elsif/unless/ternary/modifier/case-in guard condition -> true",
  "condition_false"    => "if/elsif/unless/ternary/modifier/case-in guard condition -> false",
  "operator_assignment" => "+= <-> -=, *= <-> /=, %= -> *=, **= -> *= (not ||=, &&=)"
}.freeze

Class Method Summary collapse

Class Method Details

.default?(name) ⇒ Boolean

Returns whether the operator is part of the default Tier-1 set.

Parameters:

  • name (String) —

    operator name.

Returns:

  • (Boolean) —

    true when the operator is default.



101
# File 'lib/mutineer/mutator_registry.rb', line 101

def self.default?(name) = DEFAULT_NAMES.include?(name)

.resolve(names = DEFAULT_NAMES) ⇒ Array<Class>

Resolves operator names to classes.

Parameters:

  • names (Array<String>) (defaults to: DEFAULT_NAMES) —

    operator names to resolve.

Returns:

  • (Array<Class>) —

    mutator classes in the requested order.

Raises:

  • (ArgumentError) —

    when a name is unknown.



93
94
95
# File 'lib/mutineer/mutator_registry.rb', line 93

def self.resolve(names = DEFAULT_NAMES)
  names.map { |n| ALL.fetch(n) { raise ArgumentError, "Unknown operator: #{n.inspect}" } }
end

.tier(name) ⇒ Integer

Returns the tier number for an operator name.

Parameters:

  • name (String) —

    operator name.

Returns:

  • (Integer) —

    2 for Tier-2 operators, otherwise 1.



107
# File 'lib/mutineer/mutator_registry.rb', line 107

def self.tier(name)     = TIER2_NAMES.include?(name) ? 2 : 1