lib/reek/context_builder.rb in reek-6.0.2 vs lib/reek/context_builder.rb in reek-6.0.3
- old
+ new
@@ -3,10 +3,11 @@
require_relative 'context/attribute_context'
require_relative 'context/class_context'
require_relative 'context/ghost_context'
require_relative 'context/method_context'
require_relative 'context/module_context'
+require_relative 'context/refinement_context'
require_relative 'context/root_context'
require_relative 'context/send_context'
require_relative 'context/singleton_attribute_context'
require_relative 'context/singleton_method_context'
require_relative 'ast/node'
@@ -18,11 +19,11 @@
#
# TODO: This class is responsible for statements and reference
# counting. Ideally `ContextBuilder` would only build up the context tree and leave the
# statement and reference counting to the contexts.
#
- # @quality :reek:TooManyMethods { max_methods: 31 }
+ # @quality :reek:TooManyMethods { max_methods: 32 }
# @quality :reek:UnusedPrivateMethod { exclude: [ !ruby/regexp /process_/ ] }
# @quality :reek:DataClump
class ContextBuilder
attr_reader :context_tree
@@ -261,13 +262,20 @@
#
# list.map { |element| puts element }
#
# Counts non-empty blocks as one statement.
#
+ # A refinement block is handled differently and causes a RefinementContext
+ # to be opened.
+ #
def process_block(exp, _parent)
increase_statement_count_by(exp.block)
- process(exp)
+ if exp.call.name == :refine
+ handle_refinement_block(exp)
+ else
+ process(exp)
+ end
end
# Handles `begin` and `kwbegin` nodes. `begin` nodes are created implicitly
# e.g. when parsing method bodies (see example below), `kwbegin` nodes are created
# by explicitly using the `begin` keyword.
@@ -503,9 +511,15 @@
# @return [Context::*Context] the context that was appended
#
def append_new_context(klass, *args)
klass.new(*args).tap do |new_context|
new_context.register_with_parent(current_context)
+ end
+ end
+
+ def handle_refinement_block(exp)
+ inside_new_context(Context::RefinementContext, exp) do
+ process(exp)
end
end
def handle_send_for_modules(exp)
arg_names = exp.args.map { |arg| arg.children.first }