Class: Imap::Backup::Serializer::DelayedMetadataSerializer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/imap/backup/serializer/delayed_metadata_serializer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(serializer:) ⇒ DelayedMetadataSerializer

Returns a new instance of DelayedMetadataSerializer.



15
16
17
18
# File 'lib/imap/backup/serializer/delayed_metadata_serializer.rb', line 15

def initialize(serializer:)
  @serializer = serializer
  @tsx = nil
end

Instance Attribute Details

#serializerObject (readonly)

Returns the value of attribute serializer.



11
12
13
# File 'lib/imap/backup/serializer/delayed_metadata_serializer.rb', line 11

def serializer
  @serializer
end

Instance Method Details

#append(uid, message, flags) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/imap/backup/serializer/delayed_metadata_serializer.rb', line 32

def append(uid, message, flags)
  tsx.fail_outside_transaction!(:append)
  mboxrd_message = Email::Mboxrd::Message.new(message)
  serialized = mboxrd_message.to_serialized
  tsx.data[:metadata] << {uid: uid, length: serialized.bytesize, flags: flags}
  mbox.append(serialized)
end

#transaction(&block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/imap/backup/serializer/delayed_metadata_serializer.rb', line 20

def transaction(&block)
  tsx.fail_in_transaction!(:transaction, message: "nested transactions are not supported")

  tsx.begin({metadata: []}) do
    mbox.transaction do
      block.call

      commit
    end
  end
end