class Reek::Context::ModuleContext
A context wrapper for any module found in a syntax tree.
Constants
- CONSTANT_SEXP_TYPES
Attributes
Public Class Methods
Source
# File lib/reek/context/module_context.rb, line 16 def initialize(exp) super @visibility_tracker = VisibilityTracker.new end
Reek::Context::CodeContext::new
Public Instance Methods
Source
# File lib/reek/context/module_context.rb, line 28 def append_child_context(child) visibility_tracker.apply_visibility(child) super end
Register a child context. The child’s parent context should be equal to the current context.
This makes the current context responsible for setting the child’s visibility.
@param child [CodeContext] the child context to register
Reek::Context::CodeContext#append_child_context
Source
# File lib/reek/context/module_context.rb, line 42 def attribute_context_class AttributeContext end
Return the correct class for child attribute contexts. For ModuleContext
, this is the class that represents instance attributes.
Source
# File lib/reek/context/module_context.rb, line 46 def defined_instance_methods(visibility: :any) return instance_method_children if visibility == :any instance_method_children.select { |child| child.visibility == visibility } end
Source
# File lib/reek/context/module_context.rb, line 69 def descriptively_commented? CodeComment.new(comment: exp.leading_comment).descriptive? end
Source
# File lib/reek/context/module_context.rb, line 52 def instance_method_calls instance_method_children.flat_map do |context| context.children.grep(SendContext) end end
Source
# File lib/reek/context/module_context.rb, line 58 def instance_method_names_via_to_call instance_method_calls.flat_map(&:method_name_called_to_call).compact end
Source
# File lib/reek/context/module_context.rb, line 36 def method_context_class MethodContext end
Return the correct class for child method contexts (representing nodes of type ‘:def`). For ModuleContext
, this is the class that represents instance methods.
Source
# File lib/reek/context/module_context.rb, line 83 def namespace_module? return false if exp.type == :casgn children = exp.direct_children children.any? && children.all? { |child| CONSTANT_SEXP_TYPES.include? child.type } end
A namespace module is a module (or class) that is only there for namespacing purposes, and thus contains only nested constants, modules or classes.
However, if the module is empty, it is not considered a namespace module.
@return true if the module is a namespace module
@quality :reek:FeatureEnvy
Source
# File lib/reek/context/module_context.rb, line 65 def node_instance_methods local_nodes(:def).to_a end
@deprecated use ‘defined_instance_methods` instead
Source
# File lib/reek/context/module_context.rb, line 90 def track_visibility(visibility, names) visibility_tracker.track_visibility children: instance_method_children, visibility: visibility, names: names visibility_tracker.track_singleton_visibility children: singleton_method_children, visibility: visibility, names: names end
Private Instance Methods
Source
# File lib/reek/context/module_context.rb, line 101 def instance_method_children children.select(&:instance_method?) end
Source
# File lib/reek/context/module_context.rb, line 105 def singleton_method_children children.select(&:singleton_method?) end