Module: Tapioca::FileHelper

Included in:
Commands::AbstractDsl
Defined in:
lib/tapioca/helpers/file_helper.rb

Instance Method Summary collapse

Instance Method Details

#file_diff(filename, old_path, new_path) ⇒ Object

: (Pathname filename, Pathname | String old_path, Pathname | String new_path) -> String?



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tapioca/helpers/file_helper.rb', line 9

def file_diff(filename, old_path, new_path)
  filename = filename.to_s
  stdout, stderr, status = Open3.capture3(
    "diff",
    "-u",
    "--label=Current #{filename}",
    old_path.to_s,
    "--label=Expected #{filename} (After running `bin/tapioca dsl`)",
    new_path.to_s,
  )

  unless [0, 1].include?(status.exitstatus)
    error_msg("Failed to create #{filename} diff. #{stderr.chomp}")
    return
  end

  stdout
rescue SystemCallError => e
  error_msg("Failed to create #{filename} diff. #{e.message}")
  nil
end