From 308876fca262736a5fa36dddb3990b27fbc6e64a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 23 Nov 2008 15:31:57 -0800 Subject: [PATCH] Lazy-require tempfile for File#atomic_write --- activesupport/lib/active_support/core_ext/file/atomic.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/file/atomic.rb b/activesupport/lib/active_support/core_ext/file/atomic.rb index f988eff3d9..976d462e8e 100644 --- a/activesupport/lib/active_support/core_ext/file/atomic.rb +++ b/activesupport/lib/active_support/core_ext/file/atomic.rb @@ -1,5 +1,3 @@ -require 'tempfile' - module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module File #:nodoc: @@ -18,6 +16,8 @@ module Atomic # file.write("hello") # end def atomic_write(file_name, temp_dir = Dir.tmpdir) + require 'tempfile' unless defined?(Tempfile) + temp_file = Tempfile.new(basename(file_name), temp_dir) yield temp_file temp_file.close