Class: Ast::Crispr::Replace

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



1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
# File 'lib/ast/crispr.rb', line 1360

def call
  self.operation_profile = self.class.operation_profile
  context = context_for(content: content, source_label: source_label, target: target)
  self.matches = 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, replacement.to_s)
  self.changed = updated_content != content
rescue Error => e
  crispr_fail!(e)
end