Class: Imap::Backup::Serializer::Transaction
- Inherits:
-
Object
- Object
- Imap::Backup::Serializer::Transaction
- Defined in:
- lib/imap/backup/serializer/transaction.rb
Overview
Stores data during a transaction
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
The transaction’s stored data.
Instance Method Summary collapse
-
#begin(data, &block) ⇒ void
Runs the transaction.
-
#clear ⇒ void
Clears rollback data.
-
#fail_in_transaction!(method, message: "not supported inside trasactions") ⇒ void
Throws an exception if there is a current transaction.
-
#fail_outside_transaction!(method) ⇒ void
Throws an exception if there is not a current transaction.
- #in_transaction? ⇒ Boolean
-
#initialize(owner:) ⇒ Transaction
constructor
A new instance of Transaction.
Constructor Details
#initialize(owner:) ⇒ Transaction
Returns a new instance of Transaction.
13 14 15 16 17 |
# File 'lib/imap/backup/serializer/transaction.rb', line 13 def initialize(owner:) @data = nil @owner = owner @in_transaction = false end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the transaction’s stored data.
9 10 11 |
# File 'lib/imap/backup/serializer/transaction.rb', line 9 def data @data end |
Instance Method Details
#begin(data, &block) ⇒ void
This method returns an undefined value.
Runs the transaction
23 24 25 26 27 28 |
# File 'lib/imap/backup/serializer/transaction.rb', line 23 def begin(data, &block) @data = data @in_transaction = true block.call @in_transaction = false end |
#clear ⇒ void
This method returns an undefined value.
Clears rollback data
32 33 34 |
# File 'lib/imap/backup/serializer/transaction.rb', line 32 def clear @data = nil end |
#fail_in_transaction!(method, message: "not supported inside trasactions") ⇒ void
This method returns an undefined value.
Throws an exception if there is a current transaction
44 45 46 |
# File 'lib/imap/backup/serializer/transaction.rb', line 44 def fail_in_transaction!(method, message: "not supported inside trasactions") raise "#{owner.class}##{method} #{}" if in_transaction? end |
#fail_outside_transaction!(method) ⇒ void
This method returns an undefined value.
Throws an exception if there is not a current transaction
52 53 54 |
# File 'lib/imap/backup/serializer/transaction.rb', line 52 def fail_outside_transaction!(method) raise "#{owner.class}##{method} can only be called inside a transaction" if !in_transaction? end |
#in_transaction? ⇒ Boolean
36 37 38 |
# File 'lib/imap/backup/serializer/transaction.rb', line 36 def in_transaction? @in_transaction end |