Class: Imap::Backup::Serializer::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/serializer/transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner:) ⇒ Transaction

Returns a new instance of Transaction.



8
9
10
11
12
# File 'lib/imap/backup/serializer/transaction.rb', line 8

def initialize(owner:)
  @data = nil
  @owner = owner
  @in_transaction = false
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/imap/backup/serializer/transaction.rb', line 6

def data
  @data
end

#ownerObject (readonly)

Returns the value of attribute owner.



5
6
7
# File 'lib/imap/backup/serializer/transaction.rb', line 5

def owner
  @owner
end

Instance Method Details

#begin(data, &block) ⇒ Object



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

def begin(data, &block)
  @data = data
  @in_transaction = true
  block.call
  @in_transaction = false
end

#clearObject



21
22
23
# File 'lib/imap/backup/serializer/transaction.rb', line 21

def clear
  @data = nil
end

#fail_in_transaction!(method, message: "not supported inside trasactions") ⇒ Object



29
30
31
# File 'lib/imap/backup/serializer/transaction.rb', line 29

def fail_in_transaction!(method, message: "not supported inside trasactions")
  raise "#{owner.class}##{method} #{message}" if in_transaction?
end

#fail_outside_transaction!(method) ⇒ Object



33
34
35
# File 'lib/imap/backup/serializer/transaction.rb', line 33

def fail_outside_transaction!(method)
  raise "#{owner.class}##{method} can only be called inside a transaction" if !in_transaction?
end

#in_transaction?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/imap/backup/serializer/transaction.rb', line 25

def in_transaction?
  @in_transaction
end