Class: Contrast::Agent::Assess::Policy::Propagator::Reverse

Inherits:
Base
  • Object
show all
Defined in:
lib/contrast/agent/assess/policy/propagator/reverse.rb

Overview

Propagation that results in all the tags of the source being applied to the target in reverse of how they are in the source. The target’s preexisting tags are unaffected beyond any merging of overlapping tags.

Class Method Summary collapse

Methods inherited from Base

find_source, tracked_value?

Class Method Details

.propagate(propagation_node, preshift, target) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/contrast/agent/assess/policy/propagator/reverse.rb', line 15

def propagate propagation_node, preshift, target
  return unless (properties = Contrast::Agent::Assess::Tracker.properties!(target))

  source = find_source(propagation_node.sources[0], preshift)
  properties.copy_from(source, target, 0, propagation_node.untags)

  length = target.length
  properties.tag_keys.each do |key|
    tags = properties.fetch_tag(key)
    tags.each do |tag|
      new_end = length - tag.start_idx
      new_start = new_end - tag.length
      tag.repurpose(new_start, new_end)
    end
  end

  properties.cleanup_tags
end