diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2013-10-22 12:36:51 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2013-10-23 17:15:10 -0700 |
commit | 60f0b9406645a8b0b3faeb60da1d0a0caf3c570b (patch) | |
tree | a217b540a7aceccb98ded77f8e09dbfa90edc910 | |
parent | 632b134e5bebe06acb91e03867eb453f05fe9c1b (diff) | |
download | chef-60f0b9406645a8b0b3faeb60da1d0a0caf3c570b.tar.gz |
Use Tempfile.open to take a block
- Tempfile.new should either take a block or raise if it gets one,
silently ignoring the block is poor form.
-rw-r--r-- | lib/chef/knife/core/node_editor.rb | 3 | ||||
-rw-r--r-- | lib/chef/knife/core/ui.rb | 3 | ||||
-rw-r--r-- | lib/chef/knife/edit.rb | 2 |
3 files changed, 4 insertions, 4 deletions
diff --git a/lib/chef/knife/core/node_editor.rb b/lib/chef/knife/core/node_editor.rb index 2fe090d114..454af77690 100644 --- a/lib/chef/knife/core/node_editor.rb +++ b/lib/chef/knife/core/node_editor.rb @@ -110,7 +110,8 @@ class Chef end def tempfile_for(data) - Tempfile.new([ 'knife-edit-', '.json' ]) do |file| + Tempfile.open([ 'knife-edit-', '.json' ]) do |file| + file.sync = true file.puts data file.close diff --git a/lib/chef/knife/core/ui.rb b/lib/chef/knife/core/ui.rb index 0b39243966..dfa8c11644 100644 --- a/lib/chef/knife/core/ui.rb +++ b/lib/chef/knife/core/ui.rb @@ -166,11 +166,10 @@ class Chef output = Chef::JSONCompat.to_json_pretty(data) if (!config[:disable_editing]) - Tempfile.new([ 'knife-edit-', '.json' ]) do |tf| + Tempfile.open([ 'knife-edit-', '.json' ]) do |tf| tf.sync = true tf.puts output tf.close - raise "Please set EDITOR environment variable" unless system("#{config[:editor]} #{tf.path}") output = IO.read(tf.path) diff --git a/lib/chef/knife/edit.rb b/lib/chef/knife/edit.rb index 442b0e08c2..7408179ed0 100644 --- a/lib/chef/knife/edit.rb +++ b/lib/chef/knife/edit.rb @@ -51,7 +51,7 @@ class Chef def edit_text(text, extension) if (!config[:disable_editing]) - Tempfile.new([ 'knife-edit-', extension ]) do |file| + Tempfile.open([ 'knife-edit-', extension ]) do |file| # Write the text to a temporary file file.write(text) file.close |