Class: Reek::TreeWalker Private
- Inherits:
-
Object
- Object
- Reek::TreeWalker
- Defined in:
- lib/reek/tree_walker.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Traverses a Sexp abstract syntax tree and fires events whenever it encounters specific node types.
SMELL: This class is responsible for counting statements and for feeding each context to the smell repository.
Instance Method Summary collapse
-
#initialize(smell_repository = Smells::SmellRepository.new) ⇒ TreeWalker
constructor
private
A new instance of TreeWalker.
- #process(exp) ⇒ Object private
- #process_args(_) ⇒ Object private
- #process_begin(exp) ⇒ Object (also: #process_kwbegin) private
-
#process_block(exp) ⇒ Object
private
Statement counting.
- #process_case(exp) ⇒ Object private
- #process_def(exp) ⇒ Object private
- #process_default(exp) ⇒ Object private
- #process_defs(exp) ⇒ Object private
- #process_for(exp) ⇒ Object private
- #process_if(exp) ⇒ Object private
- #process_ivar(exp) ⇒ Object (also: #process_ivasgn) private
- #process_module(exp) ⇒ Object (also: #process_class) private
- #process_resbody(exp) ⇒ Object private
- #process_rescue(exp) ⇒ Object private
- #process_self(_) ⇒ Object (also: #process_zsuper) private
-
#process_send(exp) ⇒ Object
(also: #process_attrasgn, #process_op_asgn)
private
Recording of calls to methods and self.
- #process_when(exp) ⇒ Object private
- #process_while(exp) ⇒ Object (also: #process_until) private
Constructor Details
#initialize(smell_repository = Smells::SmellRepository.new) ⇒ TreeWalker
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of TreeWalker.
18 19 20 21 |
# File 'lib/reek/tree_walker.rb', line 18 def initialize(smell_repository = Smells::SmellRepository.new) @smell_repository = smell_repository @element = Context::RootContext.new end |
Instance Method Details
#process(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 26 27 28 29 30 31 |
# File 'lib/reek/tree_walker.rb', line 23 def process(exp) context_processor = "process_#{exp.type}" if context_processor_exists?(context_processor) send(context_processor, exp) else process_default exp end @element end |
#process_args(_) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 |
# File 'lib/reek/tree_walker.rb', line 61 def process_args(_) end |
#process_begin(exp) ⇒ Object Also known as: process_kwbegin
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
97 98 99 100 101 |
# File 'lib/reek/tree_walker.rb', line 97 def process_begin(exp) count_statement_list(exp.children) @element.count_statements(-1) process_default(exp) end |
#process_block(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Statement counting
92 93 94 95 |
# File 'lib/reek/tree_walker.rb', line 92 def process_block(exp) count_clause(exp.block) process_default(exp) end |
#process_case(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
137 138 139 140 141 |
# File 'lib/reek/tree_walker.rb', line 137 def process_case(exp) count_clause(exp.else_body) @element.count_statements(-1) process_default(exp) end |
#process_def(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
47 48 49 50 51 52 |
# File 'lib/reek/tree_walker.rb', line 47 def process_def(exp) inside_new_context(Context::MethodContext, exp) do count_clause(exp.body) process_default(exp) end end |
#process_default(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 36 37 |
# File 'lib/reek/tree_walker.rb', line 33 def process_default(exp) exp.children.each do |child| process(child) if child.is_a? AST::Node end end |
#process_defs(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 57 58 59 |
# File 'lib/reek/tree_walker.rb', line 54 def process_defs(exp) inside_new_context(Context::SingletonMethodContext, exp) do count_clause(exp.body) process_default(exp) end end |
#process_for(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
120 121 122 123 124 |
# File 'lib/reek/tree_walker.rb', line 120 def process_for(exp) count_clause(exp[3]) @element.count_statements(-1) process_default(exp) end |
#process_if(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
105 106 107 108 109 110 |
# File 'lib/reek/tree_walker.rb', line 105 def process_if(exp) count_clause(exp[2]) count_clause(exp[3]) @element.count_statements(-1) process_default(exp) end |
#process_ivar(exp) ⇒ Object Also known as: process_ivasgn
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
75 76 77 78 |
# File 'lib/reek/tree_walker.rb', line 75 def process_ivar(exp) @element.record_use_of_self process_default(exp) end |
#process_module(exp) ⇒ Object Also known as: process_class
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 42 43 |
# File 'lib/reek/tree_walker.rb', line 39 def process_module(exp) inside_new_context(Context::ModuleContext, exp) do process_default(exp) end end |
#process_resbody(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
132 133 134 135 |
# File 'lib/reek/tree_walker.rb', line 132 def process_resbody(exp) count_statement_list(exp[2..-1].compact) process_default(exp) end |
#process_rescue(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
126 127 128 129 130 |
# File 'lib/reek/tree_walker.rb', line 126 def process_rescue(exp) count_clause(exp[1]) @element.count_statements(-1) process_default(exp) end |
#process_self(_) ⇒ Object Also known as: process_zsuper
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 |
# File 'lib/reek/tree_walker.rb', line 82 def process_self(_) @element.record_use_of_self end |
#process_send(exp) ⇒ Object Also known as: process_attrasgn, process_op_asgn
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Recording of calls to methods and self
67 68 69 70 |
# File 'lib/reek/tree_walker.rb', line 67 def process_send(exp) @element.record_call_to(exp) process_default(exp) end |
#process_when(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
143 144 145 146 |
# File 'lib/reek/tree_walker.rb', line 143 def process_when(exp) count_clause(exp.body) process_default(exp) end |
#process_while(exp) ⇒ Object Also known as: process_until
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
112 113 114 115 116 |
# File 'lib/reek/tree_walker.rb', line 112 def process_while(exp) count_clause(exp[2]) @element.count_statements(-1) process_default(exp) end |