@@ -109,11 +109,10 @@ def initialize(source_buffer,
109109 @different_replacements = check_policy_value ( different_replacements )
110110 @swallowed_insertions = check_policy_value ( swallowed_insertions )
111111
112- @enforcer = method ( :enforce_policy )
113112 # We need a range that would be jugded as containing all other ranges,
114113 # including 0...0 and size...size:
115114 all_encompassing_range = @source_buffer . source_range . adjust ( begin_pos : -1 , end_pos : +1 )
116- @action_root = TreeRewriter ::Action . new ( all_encompassing_range , @enforcer )
115+ @action_root = TreeRewriter ::Action . new ( all_encompassing_range , self )
117116 end
118117
119118 ##
@@ -354,6 +353,16 @@ def insert_after_multi(range, text)
354353
355354 extend Deprecation
356355
356+ ##
357+ # @api private
358+ # reserved for TreeAction
359+ #
360+ def enforce_policy ( event )
361+ return if policy ( event ) == :accept
362+ return unless ( values = yield )
363+ trigger_policy ( event , **values )
364+ end
365+
357366 protected
358367
359368 attr_reader :action_root
@@ -369,7 +378,7 @@ def check_policy_value(value)
369378
370379 def combine ( range , attributes )
371380 range = check_range_validity ( range )
372- action = TreeRewriter ::Action . new ( range , @enforcer , **attributes )
381+ action = TreeRewriter ::Action . new ( range , self , **attributes )
373382 @action_root = @action_root . combine ( action )
374383 self
375384 end
@@ -393,12 +402,6 @@ def policy(event)
393402 instance_variable_get ( EVENT_TO_POLICY . fetch ( event ) )
394403 end
395404
396- def enforce_policy ( event )
397- return if policy ( event ) == :accept
398- return unless ( values = yield )
399- trigger_policy ( event , **values )
400- end
401-
402405 POLICY_TO_LEVEL = { warn : :warning , raise : :error } . freeze
403406 def trigger_policy ( event , range : raise , conflict : nil , **arguments )
404407 action = policy ( event )
0 commit comments