Class: Imap::Backup::Serializer::DelayedMetadataSerializer
- Inherits:
-
Object
- Object
- Imap::Backup::Serializer::DelayedMetadataSerializer
- Extended by:
- Forwardable
- Defined in:
- lib/imap/backup/serializer/delayed_metadata_serializer.rb
Instance Method Summary collapse
-
#append(uid, message, flags) ⇒ void
Appends a message to the mbox file and adds the metadata to the transaction.
-
#initialize(serializer:) ⇒ DelayedMetadataSerializer
constructor
A new instance of DelayedMetadataSerializer.
-
#transaction(&block) ⇒ void
Initializes the metadata and mailbox transactions, then calls the supplied block.
Constructor Details
#initialize(serializer:) ⇒ DelayedMetadataSerializer
Returns a new instance of DelayedMetadataSerializer.
16 17 18 19 |
# File 'lib/imap/backup/serializer/delayed_metadata_serializer.rb', line 16 def initialize(serializer:) @serializer = serializer @tsx = nil end |
Instance Method Details
#append(uid, message, flags) ⇒ void
This method returns an undefined value.
Appends a message to the mbox file and adds the metadata to the transaction
46 47 48 49 50 51 52 |
# File 'lib/imap/backup/serializer/delayed_metadata_serializer.rb', line 46 def append(uid, , flags) tsx.fail_outside_transaction!(:append) = Email::Mboxrd::Message.new() serialized = .to_serialized tsx.data[:metadata] << {uid: uid, length: serialized.bytesize, flags: flags} mbox.append(serialized) end |
#transaction(&block) ⇒ void
This method returns an undefined value.
Initializes the metadata and mailbox transactions, then calls the supplied block. Once the block has finished, commits changes to metadata
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/imap/backup/serializer/delayed_metadata_serializer.rb', line 25 def transaction(&block) tsx.fail_in_transaction!(:transaction, message: "nested transactions are not supported") tsx.begin({metadata: []}) do mbox.transaction do block.call commit serializer.reload end end end |