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 (the M4 Tier-1 + statement-removal operators per locked decision #2). The three Tier-2 operators live in ALL but are OFF by default — they only run when named via --operators or operators: in .mutineer.yml (KTD8). Keeping DEFAULT_NAMES an explicit subset (not ALL.keys) is what keeps the M4 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
}.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].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"
}.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.



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

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.



65
66
67
# File 'lib/mutineer/mutator_registry.rb', line 65

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.



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

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