Class: Ast::Crispr::Move
Instance Method Summary
collapse
included, #operation_profile
Instance Method Details
#call ⇒ Object
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
|
# File 'lib/ast/crispr.rb', line 1533
def call
self.operation_profile = self.class.operation_profile
working_content = content
if source_target
context = context_for(content: content, source_label: source_label, target: source_target)
self.source_matches = normalize_matches(source_target, context)
self.source_match_count = source_matches.size
self.captured_text = capture_text(content, source_matches)
working_content = replace_line_ranges(content, source_matches, '') unless source_matches.empty?
end
text_to_insert = replacement.nil? ? captured_text.to_s : replacement.to_s
self.updated_content =
if text_to_insert.empty?
working_content
else
updated_content, profile = insert_text(working_content, text_to_insert, destination: destination,
if_missing: if_missing, source_label: source_label)
self.destination_profile = profile
updated_content
end
self.changed = updated_content != content
rescue Error => e
crispr_fail!(e)
end
|