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
- #read(offset, length) ⇒ 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
26 27 28 29 30 |
# File 'lib/imap/backup/serializer/mbox.rb', line 26 def delete return if !exist? File.unlink(pathname) end |
#length ⇒ Object
32 33 34 35 36 |
# File 'lib/imap/backup/serializer/mbox.rb', line 32 def length return nil if !exist? File.stat(pathname).size end |
#pathname ⇒ Object
38 39 40 |
# File 'lib/imap/backup/serializer/mbox.rb', line 38 def pathname "#{folder_path}.mbox" end |
#read(offset, length) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/imap/backup/serializer/mbox.rb', line 19 def read(offset, length) File.open(pathname, "rb") do |f| f.seek offset f.read length end end |
#rename(new_path) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/imap/backup/serializer/mbox.rb', line 42 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
52 53 54 55 56 |
# File 'lib/imap/backup/serializer/mbox.rb', line 52 def rewind(length) File.open(pathname, File::RDWR | File::CREAT, 0o644) do |f| f.truncate(length) end end |
#touch ⇒ Object
58 59 60 |
# File 'lib/imap/backup/serializer/mbox.rb', line 58 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 |