Class: Imap::Backup::Serializer::Mbox
- Inherits:
-
Object
- Object
- Imap::Backup::Serializer::Mbox
- Defined in:
- lib/imap/backup/serializer/mbox.rb
Instance Attribute Summary collapse
-
#folder_path ⇒ Object
readonly
Returns the value of attribute folder_path.
Instance Method Summary collapse
- #append(message) ⇒ Object
- #delete ⇒ Object
-
#initialize(folder_path) ⇒ Mbox
constructor
A new instance of Mbox.
- #length ⇒ Object
- #pathname ⇒ Object
- #rename(new_path) ⇒ Object
- #rewind(length) ⇒ Object
- #touch ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(folder_path) ⇒ Mbox
Returns a new instance of Mbox.
5 6 7 |
# File 'lib/imap/backup/serializer/mbox.rb', line 5 def initialize(folder_path) @folder_path = folder_path end |
Instance Attribute Details
#folder_path ⇒ Object (readonly)
Returns the value of attribute folder_path.
3 4 5 |
# File 'lib/imap/backup/serializer/mbox.rb', line 3 def folder_path @folder_path end |
Instance Method Details
#append(message) ⇒ Object
13 14 15 16 17 |
# File 'lib/imap/backup/serializer/mbox.rb', line 13 def append() File.open(pathname, "ab") do |file| file.write end end |
#delete ⇒ Object
19 20 21 22 23 |
# File 'lib/imap/backup/serializer/mbox.rb', line 19 def delete return if !exist? File.unlink(pathname) end |
#length ⇒ Object
25 26 27 28 29 |
# File 'lib/imap/backup/serializer/mbox.rb', line 25 def length return nil if !exist? File.stat(pathname).size end |
#pathname ⇒ Object
31 32 33 |
# File 'lib/imap/backup/serializer/mbox.rb', line 31 def pathname "#{folder_path}.mbox" end |
#rename(new_path) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/imap/backup/serializer/mbox.rb', line 35 def rename(new_path) if exist? old_pathname = pathname @folder_path = new_path File.rename(old_pathname, pathname) else @folder_path = new_path end end |
#rewind(length) ⇒ Object
45 46 47 48 49 |
# File 'lib/imap/backup/serializer/mbox.rb', line 45 def rewind(length) File.open(pathname, File::RDWR | File::CREAT, 0o644) do |f| f.truncate(length) end end |
#touch ⇒ Object
51 52 53 |
# File 'lib/imap/backup/serializer/mbox.rb', line 51 def touch File.open(pathname, "a") {} end |
#valid? ⇒ Boolean
9 10 11 |
# File 'lib/imap/backup/serializer/mbox.rb', line 9 def valid? exist? end |