Class: SystemMail::Storage
- Inherits:
-
Object
- Object
- SystemMail::Storage
- Defined in:
- lib/system_mail/storage.rb
Overview
A class to store string data either in StringIO or in Tempfile.
Instance Method Summary collapse
- #capture {|@io.path| ... } ⇒ Object
- #clear ⇒ Object
- #file? ⇒ Boolean
-
#initialize(path = nil) ⇒ Storage
constructor
A new instance of Storage.
- #puts(data = nil) ⇒ Object
- #read ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ Storage
Returns a new instance of Storage.
9 10 11 12 |
# File 'lib/system_mail/storage.rb', line 9 def initialize(path = nil) @tmpdir = path || Dir.tmpdir @io = StringIO.new end |
Instance Method Details
#capture {|@io.path| ... } ⇒ Object
28 29 30 31 32 33 |
# File 'lib/system_mail/storage.rb', line 28 def capture ensure_tempfile @io.close yield @io.path @io.open end |
#clear ⇒ Object
39 40 41 42 |
# File 'lib/system_mail/storage.rb', line 39 def clear @io.close @io.unlink if file? end |
#file? ⇒ Boolean
35 36 37 |
# File 'lib/system_mail/storage.rb', line 35 def file? @io.kind_of?(Tempfile) end |
#puts(data = nil) ⇒ Object
14 15 16 |
# File 'lib/system_mail/storage.rb', line 14 def puts(data = nil) @io.puts(data) end |
#read ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/system_mail/storage.rb', line 18 def read if file? capture do |file_path| File.read file_path end else @io.string.dup end end |