Class: RubyCode::Views::UpdateApproval

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycode/views/update_approval.rb

Overview

Builds file update approval prompt display with diff

Class Method Summary collapse

Class Method Details

.build(file_path:, old_string:, new_string:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rubycode/views/update_approval.rb', line 9

def self.build(file_path:, old_string:, new_string:)
  pastel = Pastel.new

  [
    "",
    pastel.yellow("━" * 80),
    pastel.bold("Update Operation - Approval Required"),
    "#{pastel.cyan("File:")} #{file_path}",
    pastel.yellow("─" * 80),
    format_removal_section(pastel, old_string),
    "",
    format_addition_section(pastel, new_string),
    pastel.yellow("━" * 80)
  ].join("\n")
end

.format_addition_section(pastel, new_string) ⇒ Object



30
31
32
33
# File 'lib/rubycode/views/update_approval.rb', line 30

def self.format_addition_section(pastel, new_string)
  new_lines = new_string.lines.map { |line| pastel.green("  + #{line.chomp}") }
  [pastel.green("+ ADD:"), new_lines.join("\n")].join("\n")
end

.format_removal_section(pastel, old_string) ⇒ Object



25
26
27
28
# File 'lib/rubycode/views/update_approval.rb', line 25

def self.format_removal_section(pastel, old_string)
  old_lines = old_string.lines.map { |line| pastel.red("  - #{line.chomp}") }
  [pastel.red("- REMOVE:"), old_lines.join("\n")].join("\n")
end