Sha256: 0e5d06ee676416b01c873baff1abedde397d69571c907a851619663400ed0a6f

Contents?: true

Size: 952 Bytes

Versions: 36

Compression:

Stored size: 952 Bytes

Contents

# frozen_string_literal: true

module Mutant
  # Registry for mapping AST types to classes
  class Registry
    include Concord.new(:contents)

    # Initialize object
    #
    # @return [undefined]
    def initialize
      super({})
    end

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

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

    # Lookup class for node
    #
    # @param [Symbol] type
    #
    # @return [Class<Mutator>]
    def lookup(type)
      contents.fetch(type, Mutator::Node::Generic)
    end

  end # Registry
end # Mutant

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
mutant-0.10.30 lib/mutant/registry.rb
mutant-0.10.29 lib/mutant/registry.rb
mutant-0.10.28 lib/mutant/registry.rb
mutant-0.10.27 lib/mutant/registry.rb
mutant-0.10.26 lib/mutant/registry.rb
mutant-0.10.25 lib/mutant/registry.rb
mutant-0.10.24 lib/mutant/registry.rb
mutant-0.10.23 lib/mutant/registry.rb
mutant-0.10.22 lib/mutant/registry.rb
mutant-0.10.21 lib/mutant/registry.rb
mutant-0.10.20 lib/mutant/registry.rb
mutant-0.10.19 lib/mutant/registry.rb
mutant-0.10.18 lib/mutant/registry.rb
mutant-0.10.17 lib/mutant/registry.rb
mutant-0.10.16 lib/mutant/registry.rb
mutant-0.10.15 lib/mutant/registry.rb
mutant-0.10.14 lib/mutant/registry.rb
mutant-0.10.13 lib/mutant/registry.rb
mutant-0.10.12 lib/mutant/registry.rb
mutant-0.10.11 lib/mutant/registry.rb