class Tempfile

Public Class Methods

blank(options = {}) { |tempfile| ... } click to toggle source
# File lib/tempfile_for.rb, line 16
def self.blank(options = {})
  tempfile = TempfileFor::Tempfile.build(options)

  yield tempfile if block_given?

  tempfile.flush

  options[:read] != false ? File.read(tempfile.path, :encoding => options[:encoding]) : tempfile.copy(options)
ensure
  tempfile.close!
end
for(io_or_data, options = {}) { |tempfile| ... } click to toggle source
# File lib/tempfile_for.rb, line 7
def self.for(io_or_data, options = {})
  blank options.merge(:encoding => options[:encoding] || io_or_data.encoding) do |tempfile|
    tempfile.write_ext io_or_data
    tempfile.flush

    yield tempfile if block_given?
  end
end