Class: Reek::Context::MethodContext Private

Inherits:
CodeContext show all
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

SingletonMethodContext

Instance Attribute Summary collapse

Attributes inherited from CodeContext

#exp

Instance Method Summary collapse

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_statementsObject (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

#parametersObject (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

#refsObject (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_receiversObject

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_selfObject

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.

Returns:

  • (Boolean)


63
64
65
# File 'lib/reek/context/method_context.rb', line 63

def references_self?
  exp.depends_on_instance?
end

#unused_paramsObject

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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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