Class: Ast::Crispr::DeleteBatch

Inherits:
Actor
  • Object
show all
Includes:
OperationProfilable, OperationSupport
Defined in:
lib/ast/crispr.rb

Instance Method Summary collapse

Methods included from OperationProfilable

included, #operation_profile

Instance Method Details

#callObject



1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
# File 'lib/ast/crispr.rb', line 1445

def call
  self.operation_profile = self.class.operation_profile
  selector_targets = Array(targets)
  if selector_targets.empty?
    self.updated_content = content
    self.changed = false
    return
  end

  context = context_for_targets(content: content, source_label: source_label, targets: selector_targets)
  self.matches = selector_targets.flat_map { |target| normalize_matches(target, context) }
  self.match_count = matches.size
  self.captured_text = capture_text(content, matches)
  if matches.empty?
    self.updated_content = content
    self.changed = false
    return
  end

  self.updated_content = replace_line_ranges(content, matches, '')
  self.changed = updated_content != content
rescue Error => e
  crispr_fail!(e)
end