Class: Siege::TempFile
- Inherits:
-
Object
- Object
- Siege::TempFile
- Defined in:
- lib/siege/temp_file.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(content = nil) ⇒ TempFile
constructor
A new instance of TempFile.
- #read ⇒ Object
- #write(contents) ⇒ Object
Constructor Details
#initialize(content = nil) ⇒ TempFile
Returns a new instance of TempFile.
14 15 16 17 18 |
# File 'lib/siege/temp_file.rb', line 14 def initialize(content = nil) file = [rand(6_251_983), '_', Time.now.to_i].join @name = File.(file, Dir.tmpdir) write(content) if content end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/siege/temp_file.rb', line 12 def name @name end |
Class Method Details
.with_content(content) ⇒ Object
7 8 9 |
# File 'lib/siege/temp_file.rb', line 7 def with_content(content) new content end |
Instance Method Details
#delete ⇒ Object
24 25 26 |
# File 'lib/siege/temp_file.rb', line 24 def delete File.delete(@name) end |
#read ⇒ Object
20 21 22 |
# File 'lib/siege/temp_file.rb', line 20 def read File.read(@name) end |
#write(contents) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/siege/temp_file.rb', line 28 def write(contents) file = File.new(@name, 'w') file.puts(contents) file.close at_exit { File.delete(@name) } end |