Class: Reek::Context::MethodContext Private
- Inherits:
-
CodeContext
- Object
- CodeContext
- Reek::Context::MethodContext
- Defined in:
- lib/reek/context/method_context.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.
A context wrapper for any method definition found in a syntax tree.
Direct Known Subclasses
Instance Attribute Summary collapse
- #num_statements ⇒ Object readonly private
- #parameters ⇒ Object readonly private
- #refs ⇒ Object readonly private
Attributes inherited from CodeContext
Instance Method Summary collapse
- #count_statements(num) ⇒ Object private
- #envious_receivers ⇒ Object private
-
#initialize(outer, exp) ⇒ MethodContext
constructor
private
A new instance of MethodContext.
- #record_call_to(exp) ⇒ Object private
- #record_use_of_self ⇒ Object private
- #references_self? ⇒ Boolean private
- #unused_params ⇒ Object private
- #uses_param?(param) ⇒ Boolean private
- #uses_super_with_implicit_arguments? ⇒ Boolean private
Methods inherited from CodeContext
#config_for, #each_node, #full_name, #local_nodes, #matches?, #method_missing, #name, #num_methods
Constructor Details
#initialize(outer, exp) ⇒ MethodContext
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 MethodContext.
29 30 31 32 33 34 35 |
# File 'lib/reek/context/method_context.rb', line 29 def initialize(outer, exp) super @parameters = exp.parameters.dup @parameters.extend MethodParameters @num_statements = 0 @refs = AST::ObjectRefs.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Reek::Context::CodeContext
Instance Attribute Details
#num_statements ⇒ Object (readonly)
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.
27 28 29 |
# File 'lib/reek/context/method_context.rb', line 27 def num_statements @num_statements end |
#parameters ⇒ Object (readonly)
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.
25 26 27 |
# File 'lib/reek/context/method_context.rb', line 25 def parameters @parameters end |
#refs ⇒ Object (readonly)
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.
26 27 28 |
# File 'lib/reek/context/method_context.rb', line 26 def refs @refs end |
Instance Method Details
#count_statements(num) ⇒ 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.
37 38 39 |
# File 'lib/reek/context/method_context.rb', line 37 def count_statements(num) @num_statements += num end |
#envious_receivers ⇒ 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.
58 59 60 61 |
# File 'lib/reek/context/method_context.rb', line 58 def envious_receivers return [] if @refs.self_is_max? @refs.max_keys end |
#record_call_to(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.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/reek/context/method_context.rb', line 41 def record_call_to(exp) receiver, meth = exp[1..2] receiver ||= [:self] case receiver[0] when :lvasgn @refs.record_reference_to(receiver.name) when :lvar @refs.record_reference_to(receiver.name) unless meth == :new when :self @refs.record_reference_to(:self) end end |
#record_use_of_self ⇒ 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 |
# File 'lib/reek/context/method_context.rb', line 54 def record_use_of_self @refs.record_reference_to(:self) end |
#references_self? ⇒ Boolean
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.
63 64 65 |
# File 'lib/reek/context/method_context.rb', line 63 def references_self? exp.depends_on_instance? end |
#unused_params ⇒ 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.
71 72 73 74 75 76 77 |
# File 'lib/reek/context/method_context.rb', line 71 def unused_params exp.arguments.select do |param| next if param.anonymous_splat? next if param.marked_unused? !uses_param? param.plain_name end end |
#uses_param?(param) ⇒ Boolean
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.
67 68 69 |
# File 'lib/reek/context/method_context.rb', line 67 def uses_param?(param) local_nodes(:lvar).find { |node| node.var_name == param.to_sym } end |
#uses_super_with_implicit_arguments? ⇒ Boolean
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.
79 80 81 |
# File 'lib/reek/context/method_context.rb', line 79 def uses_super_with_implicit_arguments? (body = exp.body) && body.contains_nested_node?(:zsuper) end |