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

Instance Method Summary collapse

Class Attribute Details

.use_transactionsObject

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
# File 'lib/rubydora/transactions.rb', line 75

def append_to_transactions_log(method, options = {})
  return unless Rubydora::Transactions.use_transactions
  return if transaction_is_redundant?(method, options)
  options[:foxml] = export(:pid => options[:pid], :context => :archive) if options[:foxml] == true
  transactions_log.unshift([method, options])
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

Returns:

  • (Boolean)


87
88
89
90
91
92
93
# File 'lib/rubydora/transactions.rb', line 87

def transaction_is_redundant?(method, options)
  return true if transactions_log.any? { |(t_method, t_options)|
    # these methods will rollback ANY object change that happens after it, so there's no need to track future changes to this object
    t_options[:pid] == options[:pid] && [:ingest, :purge_object, :modify_datastream, :purge_datastream].include?(t_method)
  }
  false
end

#transactions_logObject

The repository transaction log.



83
84
85
# File 'lib/rubydora/transactions.rb', line 83

def transactions_log
  @log ||= []
end