Class: Chef::Util::Diff
- Includes:
- Mixin::ShellOut
- Defined in:
- lib/chef/util/diff.rb
Constant Summary
Constants included from Mixin::ShellOut
Mixin::ShellOut::DEPRECATED_OPTIONS
Instance Method Summary collapse
- #diff(old_file, new_file) ⇒ Object
-
#for_output ⇒ Object
@todo: to_a, to_s, to_json, inspect defs, accessors for @diff and @error @todo: move coercion to UTF-8 into to_json @todo: replace shellout to diff -u with diff-lcs gem.
- #for_reporting ⇒ Object
- #use_tempfile_if_missing(file) {|file| ... } ⇒ Object
Methods included from Mixin::ShellOut
#run_command_compatible_options, #shell_out, #shell_out!
Instance Method Details
#diff(old_file, new_file) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/chef/util/diff.rb', line 54 def diff(old_file, new_file) use_tempfile_if_missing(old_file) do |old_file| use_tempfile_if_missing(new_file) do |new_file| @error = do_diff(old_file, new_file) end end end |
#for_output ⇒ Object
@todo: to_a, to_s, to_json, inspect defs, accessors for @diff and @error @todo: move coercion to UTF-8 into to_json @todo: replace shellout to diff -u with diff-lcs gem
29 30 31 32 |
# File 'lib/chef/util/diff.rb', line 29 def for_output # formatted output to a terminal uses arrays of strings and returns error strings @diff.nil? ? [ @error ] : @diff end |
#for_reporting ⇒ Object
34 35 36 37 38 |
# File 'lib/chef/util/diff.rb', line 34 def for_reporting # caller needs to ensure that new files aren't posted to resource reporting return nil if @diff.nil? @diff.join("\\n") end |
#use_tempfile_if_missing(file) {|file| ... } ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/chef/util/diff.rb', line 40 def use_tempfile_if_missing(file) tempfile = nil unless File.exists?(file) Chef::Log.debug("file #{file} does not exist to diff against, using empty tempfile") tempfile = Tempfile.new("chef-diff") file = tempfile.path end yield file unless tempfile.nil? tempfile.close tempfile.unlink end end |