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.
-
#savepoint ⇒ Object
readonly
Returns the value of attribute savepoint.
Instance Method Summary collapse
- #append(message) ⇒ Object
- #delete ⇒ Object
- #exist? ⇒ Boolean
-
#initialize(folder_path) ⇒ Mbox
constructor
A new instance of Mbox.
- #length ⇒ Object
- #pathname ⇒ Object
- #read(offset, length) ⇒ Object
- #rename(new_path) ⇒ Object
- #rollback ⇒ Object
- #touch ⇒ Object
- #transaction(&block) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(folder_path) ⇒ Mbox
Returns a new instance of Mbox.
10 11 12 13 |
# File 'lib/imap/backup/serializer/mbox.rb', line 10 def initialize(folder_path) @folder_path = folder_path @tsx = nil end |
Instance Attribute Details
#folder_path ⇒ Object (readonly)
Returns the value of attribute folder_path.
7 8 9 |
# File 'lib/imap/backup/serializer/mbox.rb', line 7 def folder_path @folder_path end |
#savepoint ⇒ Object (readonly)
Returns the value of attribute savepoint.
8 9 10 |
# File 'lib/imap/backup/serializer/mbox.rb', line 8 def savepoint @savepoint end |
Instance Method Details
#append(message) ⇒ Object
40 41 42 43 44 |
# File 'lib/imap/backup/serializer/mbox.rb', line 40 def append() File.open(pathname, "ab") do |file| file.write end end |
#delete ⇒ Object
53 54 55 56 57 |
# File 'lib/imap/backup/serializer/mbox.rb', line 53 def delete return if !exist? File.unlink(pathname) end |
#exist? ⇒ Boolean
59 60 61 |
# File 'lib/imap/backup/serializer/mbox.rb', line 59 def exist? File.exist?(pathname) end |
#length ⇒ Object
63 64 65 66 67 |
# File 'lib/imap/backup/serializer/mbox.rb', line 63 def length return nil if !exist? File.stat(pathname).size end |
#pathname ⇒ Object
69 70 71 |
# File 'lib/imap/backup/serializer/mbox.rb', line 69 def pathname "#{folder_path}.mbox" end |
#read(offset, length) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/imap/backup/serializer/mbox.rb', line 46 def read(offset, length) File.open(pathname, "rb") do |f| f.seek offset f.read length end end |
#rename(new_path) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/imap/backup/serializer/mbox.rb', line 73 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 |
#rollback ⇒ Object
30 31 32 33 34 |
# File 'lib/imap/backup/serializer/mbox.rb', line 30 def rollback tsx.fail_outside_transaction!(:rollback) rewind(tsx.data[:savepoint][:length]) end |
#touch ⇒ Object
83 84 85 |
# File 'lib/imap/backup/serializer/mbox.rb', line 83 def touch File.open(pathname, "a") {} end |
#transaction(&block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/imap/backup/serializer/mbox.rb', line 15 def transaction(&block) tsx.fail_in_transaction!(:transaction, message: "nested transactions are not supported") tsx.begin({savepoint: {length: length}}) do block.call rescue StandardError => e rollback raise e rescue SignalException => e Logger.logger.error "#{self.class} handling #{e.class}" rollback raise e end end |
#valid? ⇒ Boolean
36 37 38 |
# File 'lib/imap/backup/serializer/mbox.rb', line 36 def valid? exist? end |