Sha256: 93c2e5d2daaa8279c7f7068cbaf18ad2f6b7c868871aba2ef639672c309c0ee3

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

module Mutant
  class Mutator
    # Registry for mutators
    class Registry

      # Initialize object
      #
      # @return [undefined]
      #
      # @api private
      def initialize
        @registry = {}
      end

      # Raised when the type is an invalid type
      RegistryError = Class.new(TypeError)

      # Register mutator class for AST node class
      #
      # @param [Symbol] type
      # @param [Class:Mutator] mutator
      #
      # @return [self]
      #
      # @api private
      def register(type, mutator)
        fail RegistryError, "Invalid type registration: #{type}" unless AST::Types::ALL.include?(type)
        fail RegistryError, "Duplicate type registration: #{type}" if @registry.key?(type)
        @registry[type] = mutator
        self
      end

      # Lookup mutator class for node
      #
      # @param [Parser::AST::Node] node
      #
      # @return [Class]
      #
      # @raise [ArgumentError]
      #   raises argument error when mutator class cannot be found
      #
      # @api private
      def lookup(node)
        type = node.type
        @registry.fetch(type) do
          fail RegistryError, "No mutator to handle: #{type.inspect}"
        end
      end

    end # Registry

    REGISTRY = Registry.new

  end # Mutator
end # Mutant

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mutant-0.8.8 lib/mutant/mutator/registry.rb
mutant-0.8.7 lib/mutant/mutator/registry.rb
mutant-0.8.6 lib/mutant/mutator/registry.rb
mutant-0.8.5 lib/mutant/mutator/registry.rb
mutant-0.8.4 lib/mutant/mutator/registry.rb
mutant-0.8.3 lib/mutant/mutator/registry.rb
mutant-0.8.2 lib/mutant/mutator/registry.rb
mutant-0.8.1 lib/mutant/mutator/registry.rb