class TempfileFor::Tempfile

Public Class Methods

build(options = {}) click to toggle source
# File lib/tempfile_for/tempfile.rb, line 6
def self.build(options = {})
  open options[:suffix] ? ["tempfile", options[:suffix]] : "tempfile", :encoding => options[:encoding]
end

Public Instance Methods

copy(options = {}) click to toggle source
# File lib/tempfile_for/tempfile.rb, line 10
def copy(options = {})
  tempfile = self.class.build(options)

  File.open(path, :encoding => options[:encoding]) { |stream| tempfile.write_ext stream }

  tempfile.rewind
  tempfile
end
write_ext(io_or_data) click to toggle source
# File lib/tempfile_for/tempfile.rb, line 19
def write_ext(io_or_data)
  if io_or_data.respond_to?(:read)
    while data = io_or_data.read(1024)
      write data
    end
  else
    write io_or_data
  end
end