Class: Reek::Source::AstNodeClassMap

Inherits:
Object
  • Object
show all
Defined in:
lib/reek/source/ast_node_class_map.rb

Overview

Maps AST node types to sublasses of AstNode extended with the relevant utility modules.

Instance Method Summary collapse

Constructor Details

#initializeAstNodeClassMap

Returns a new instance of AstNodeClassMap


10
11
12
# File 'lib/reek/source/ast_node_class_map.rb', line 10

def initialize
  @klass_map = {}
end

Instance Method Details

#extension_mapObject


23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/reek/source/ast_node_class_map.rb', line 23

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

#klass_for(type) ⇒ Object


14
15
16
17
18
19
20
21
# File 'lib/reek/source/ast_node_class_map.rb', line 14

def klass_for(type)
  @klass_map[type] ||=
    begin
      klass = Class.new(AstNode)
      klass.send :include, extension_map[type] if extension_map[type]
      klass.send :include, SexpNode
    end
end