Class: Reek::Context::MethodContext
Overview
A context wrapper for any method definition found in a syntax tree.
Instance Attribute Summary collapse
Attributes inherited from CodeContext
#children, #exp, #parent, #statement_counter
Instance Method Summary
collapse
Methods inherited from CodeContext
#append_child_context, #config_for, #configuration_via_code_commment, #each, #full_name, #local_nodes, #matches?, #number_of_statements, #parent_config_for, #record_call_to, #record_use_of_self, #register_with_parent
Constructor Details
#initialize(exp, parent_exp) ⇒ MethodContext
Returns a new instance of MethodContext.
15
16
17
18
19
|
# File 'lib/reek/context/method_context.rb', line 15
def initialize(exp, parent_exp)
@parent_exp = parent_exp
@visibility = :public
super(exp)
end
|
Instance Attribute Details
#parent_exp ⇒ Object
Returns the value of attribute parent_exp.
90
91
92
|
# File 'lib/reek/context/method_context.rb', line 90
def parent_exp
@parent_exp
end
|
#refs ⇒ Object
Returns the value of attribute refs.
13
14
15
|
# File 'lib/reek/context/method_context.rb', line 13
def refs
@refs
end
|
#visibility ⇒ Object
Returns the value of attribute visibility.
12
13
14
|
# File 'lib/reek/context/method_context.rb', line 12
def visibility
@visibility
end
|
Instance Method Details
#apply_current_visibility(current_visibility) ⇒ Object
68
69
70
|
# File 'lib/reek/context/method_context.rb', line 68
def apply_current_visibility(current_visibility)
self.visibility = current_visibility
end
|
#default_assignments ⇒ Object
51
52
53
54
|
# File 'lib/reek/context/method_context.rb', line 51
def default_assignments
@default_assignments ||=
exp.parameters.select(&:optional_argument?).map(&:children)
end
|
80
81
82
83
84
85
86
|
# File 'lib/reek/context/method_context.rb', line 80
def
own = super
return own unless own.empty?
return parent_exp. if parent_exp
''
end
|
#instance_method? ⇒ Boolean
64
65
66
|
# File 'lib/reek/context/method_context.rb', line 64
def instance_method?
true
end
|
#method_context_class ⇒ Object
56
57
58
|
# File 'lib/reek/context/method_context.rb', line 56
def method_context_class
self.class
end
|
#module_function? ⇒ Boolean
72
73
74
|
# File 'lib/reek/context/method_context.rb', line 72
def module_function?
visibility == :module_function
end
|
#non_public_visibility? ⇒ Boolean
76
77
78
|
# File 'lib/reek/context/method_context.rb', line 76
def non_public_visibility?
visibility != :public
end
|
#references_self? ⇒ Boolean
21
22
23
|
# File 'lib/reek/context/method_context.rb', line 21
def references_self?
exp.depends_on_instance?
end
|
#singleton_method? ⇒ Boolean
60
61
62
|
# File 'lib/reek/context/method_context.rb', line 60
def singleton_method?
false
end
|
#unused_params ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/reek/context/method_context.rb', line 39
def unused_params
exp.arguments.reject do |param|
param.anonymous_splat? ||
param.marked_unused? ||
uses_param?(param)
end
end
|
#uses_param?(param) ⇒ Boolean
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/reek/context/method_context.rb', line 25
def uses_param?(param)
local_nodes([:lvar, :lvasgn]).find { |node| node.var_name == param.name }
end
|
#uses_super_with_implicit_arguments? ⇒ Boolean
47
48
49
|
# File 'lib/reek/context/method_context.rb', line 47
def uses_super_with_implicit_arguments?
(body = exp.body) && body.contains_nested_node?(:zsuper)
end
|