Module: Rabbit::TemporaryFile

Defined in:
lib/rabbit/utils.rb

Class Method Summary collapse

Class Method Details

.create(options = {}) {|temp| ... } ⇒ Object

Yields:

  • (temp)


520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/rabbit/utils.rb', line 520

def create(options={})
  extension = options[:extension]
  content = options[:content]
  source = options[:source]
  if source
    extension ||= source.extension
    content   ||= source.read
  end

  prefix = ["rabbit", options[:prefix]].compact.join("-") + "-"
  if extension
    basename = [prefix, ".#{extension}"]
  else
    basename = prefix
  end
  temp = Tempfile.new(basename)
  if content
    temp.binmode
    temp.print(content)
    temp.close
  end
  yield temp
end