Class: Tempfile
- Inherits:
-
Object
- Object
- Tempfile
- Defined in:
- lib/tempfile_for.rb
Direct Known Subclasses
Class Method Summary collapse
Class Method Details
.blank(options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tempfile_for.rb', line 16 def self.blank( = {}) tempfile = TempfileFor::Tempfile.build() yield tempfile if block_given? tempfile.flush [:read] != false ? File.read(tempfile.path, :encoding => [:encoding]) : tempfile.copy() ensure tempfile.close! end |
.for(io_or_data, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/tempfile_for.rb', line 7 def self.for(io_or_data, = {}) blank .merge(:encoding => [:encoding] || io_or_data.encoding) do |tempfile| tempfile.write_ext io_or_data tempfile.flush yield tempfile if block_given? end end |