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.
11 12 13 14 15 |
# File 'lib/imap/backup/serializer/transaction.rb', line 11 def initialize(owner:) @data = nil @owner = owner @in_transaction = false end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the transaction’s stored data.
7 8 9 |
# File 'lib/imap/backup/serializer/transaction.rb', line 7 def data @data end |
Instance Method Details
#begin(data, &block) ⇒ void
This method returns an undefined value.
Runs the transaction
21 22 23 24 25 26 |
# File 'lib/imap/backup/serializer/transaction.rb', line 21 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
30 31 32 |
# File 'lib/imap/backup/serializer/transaction.rb', line 30 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
42 43 44 |
# File 'lib/imap/backup/serializer/transaction.rb', line 42 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
50 51 52 |
# File 'lib/imap/backup/serializer/transaction.rb', line 50 def fail_outside_transaction!(method) raise "#{owner.class}##{method} can only be called inside a transaction" if !in_transaction? end |
#in_transaction? ⇒ Boolean
34 35 36 |
# File 'lib/imap/backup/serializer/transaction.rb', line 34 def in_transaction? @in_transaction end |