Module: Rubydora::Transactions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rubydora/transactions.rb
Overview
Extremely basic (and naive) ‘transaction’ support for Rubydora. This isn’t really intended to be used in a production-like situation – more for rolling back (small) changes during testing.
Class Attribute Summary collapse
-
.use_transactions ⇒ Object
Returns the value of attribute use_transactions.
Instance Method Summary collapse
-
#append_to_transactions_log(method, options = {}) ⇒ Object
Unshift a transaction entry onto the transaction logs.
-
#transaction(&block) ⇒ Object
Start a transaction.
- #transaction_is_redundant?(method, options) ⇒ Boolean
-
#transactions_log ⇒ Object
The repository transaction log.
Class Attribute Details
.use_transactions ⇒ Object
Returns the value of attribute use_transactions.
9 10 11 |
# File 'lib/rubydora/transactions.rb', line 9 def use_transactions @use_transactions end |
Instance Method Details
#append_to_transactions_log(method, options = {}) ⇒ Object
Unshift a transaction entry onto the transaction logs. We want these entries in reverse-chronological order for ease of undoing..
75 76 77 78 79 80 81 82 |
# File 'lib/rubydora/transactions.rb', line 75 def append_to_transactions_log method, = {} return unless Rubydora::Transactions.use_transactions unless transaction_is_redundant?(method, ) [:foxml] = export(:pid => [:pid], :context => :archive) if [:foxml] == true transactions_log.unshift([method, ]) end end |
#transaction(&block) ⇒ Object
Start a transaction
67 68 69 70 |
# File 'lib/rubydora/transactions.rb', line 67 def transaction &block Transaction.new self, &block self.transactions_log.clear end |
#transaction_is_redundant?(method, options) ⇒ Boolean
89 90 91 92 93 94 95 96 |
# File 'lib/rubydora/transactions.rb', line 89 def transaction_is_redundant? method, return true if transactions_log.any? { |(t_method, )| # these methods will rollback ANY object change that happens after it, so there's no need to track future changes to this object [:pid] == [:pid] and [:ingest, :purge_object, :modify_datastream, :purge_datastream].include? t_method } false end |
#transactions_log ⇒ Object
The repository transaction log.
85 86 87 |
# File 'lib/rubydora/transactions.rb', line 85 def transactions_log @log ||= [] end |