Class: Reek::Source::TreeDresser

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

Overview

Adorns an abstract syntax tree with mix-in modules to make accessing the tree more understandable and less implementation-dependent.

Instance Method Summary collapse

Constructor Details

#initialize(klass_map = AstNodeClassMap.new) ⇒ TreeDresser


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

def initialize(klass_map = AstNodeClassMap.new)
  @klass_map = klass_map
end

Instance Method Details

#dress(sexp, comment_map) ⇒ Object


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

def dress(sexp, comment_map)
  return sexp unless sexp.is_a? AST::Node
  type = sexp.type
  children = sexp.children.map { |child| dress(child, comment_map) }
  comments = comment_map[sexp]
  @klass_map.klass_for(type).new(type, children,
                                 location: sexp.loc, comments: comments)
end