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.



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

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

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

Instance Method Details

#begin(data, &block) ⇒ Object



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

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

#clearObject



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

def clear
  @data = nil
end

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



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

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

#fail_outside_transaction!(method) ⇒ Object



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

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)


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

def in_transaction?
  @in_transaction
end