Class: Reek::AST::ASTNodeClassMap
- Inherits:
-
Object
- Object
- Reek::AST::ASTNodeClassMap
- Defined in:
- lib/reek/ast/ast_node_class_map.rb
Overview
Maps AST node types to sublasses of ASTNode extended with the relevant utility modules.
Instance Attribute Summary collapse
-
#klass_map ⇒ Object
readonly
private
Returns the value of attribute klass_map.
Instance Method Summary collapse
- #extension_map ⇒ Object
-
#initialize ⇒ ASTNodeClassMap
constructor
A new instance of ASTNodeClassMap.
- #klass_for(type) ⇒ Object
Constructor Details
#initialize ⇒ ASTNodeClassMap
Returns a new instance of ASTNodeClassMap.
12 13 14 |
# File 'lib/reek/ast/ast_node_class_map.rb', line 12 def initialize @klass_map = {} end |
Instance Attribute Details
#klass_map ⇒ Object (readonly, private)
Returns the value of attribute klass_map.
39 40 41 |
# File 'lib/reek/ast/ast_node_class_map.rb', line 39 def klass_map @klass_map end |
Instance Method Details
#extension_map ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/reek/ast/ast_node_class_map.rb', line 24 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 assoc.to_h end end |
#klass_for(type) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/reek/ast/ast_node_class_map.rb', line 16 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 |