Sha256: 8725d488ed1729cc1c7efaabfb25fd8c783ae06086dff29046cd931b8e05511e

Contents?: true

Size: 934 Bytes

Versions: 15

Compression:

Stored size: 934 Bytes

Contents

require_relative 'node'
require_relative 'sexp_extensions'

module Reek
  module AST
    # Maps AST node types to sublasses of ASTNode extended with the relevant
    # utility modules.
    #
    class ASTNodeClassMap
      def initialize
        @klass_map = {}
      end

      def klass_for(type)
        klass_map[type] ||= Class.new(Node).tap do |klass|
          extension = extension_map[type]
          # TODO: map node type to constant directly.
          klass.send :include, extension if extension
        end
      end

      def extension_map
        @extension_map ||=
          begin
            assoc = SexpExtensions.constants.map do |const|
              [
                const.to_s.sub(/Node$/, '').downcase.to_sym,
                SexpExtensions.const_get(const)
              ]
            end
            Hash[assoc]
          end
      end

      private

      private_attr_reader :klass_map
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
reek-3.10.1 lib/reek/ast/ast_node_class_map.rb
reek-3.10.0 lib/reek/ast/ast_node_class_map.rb
reek-3.9.1 lib/reek/ast/ast_node_class_map.rb
reek-3.9.0 lib/reek/ast/ast_node_class_map.rb
reek-3.8.3 lib/reek/ast/ast_node_class_map.rb
reek-3.8.2 lib/reek/ast/ast_node_class_map.rb
reek-3.8.1 lib/reek/ast/ast_node_class_map.rb
reek-3.8.0 lib/reek/ast/ast_node_class_map.rb
reek-3.7.1 lib/reek/ast/ast_node_class_map.rb
reek-3.7.0 lib/reek/ast/ast_node_class_map.rb
reek-3.6.1 lib/reek/ast/ast_node_class_map.rb
reek-3.6.0 lib/reek/ast/ast_node_class_map.rb
reek-3.5.0 lib/reek/ast/ast_node_class_map.rb
reek-3.4.1 lib/reek/ast/ast_node_class_map.rb
reek-3.4.0 lib/reek/ast/ast_node_class_map.rb