Class: Rubydora::Transaction
- Inherits:
-
Object
- Object
- Rubydora::Transaction
- Includes:
- Hooks
- Defined in:
- lib/rubydora/transactions.rb
Instance Attribute Summary collapse
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
-
#initialize(repository, &block) ⇒ Transaction
constructor
A new instance of Transaction.
-
#rollback ⇒ Object
Roll-back transactions by reversing their outcomes (or, in some cases, re-ingesting the object at the previous state..
- #with_transactions {|_self| ... } ⇒ Object
- #without_transactions {|_self| ... } ⇒ Object
Constructor Details
#initialize(repository, &block) ⇒ Transaction
Returns a new instance of Transaction.
101 102 103 104 |
# File 'lib/rubydora/transactions.rb', line 101 def initialize(repository, &block) @repository = repository with_transactions(&block) end |
Instance Attribute Details
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
97 98 99 |
# File 'lib/rubydora/transactions.rb', line 97 def repository @repository end |
Instance Method Details
#rollback ⇒ Object
Roll-back transactions by reversing their outcomes (or, in some cases, re-ingesting the object at the previous state.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/rubydora/transactions.rb', line 123 def rollback without_transactions do repository.transactions_log.delete_if do |(method, )| begin case method when :ingest repository.purge_object :pid => [:pid] when :modify_object repository.modify_object when :add_datastream repository.purge_datastream :pid => [:pid], :dsid => [:dsid] when :add_relationship repository.purge_relationship [:options].merge(:pid => [:pid]) when :purge_relationship repository.add_relationship [:options].merge(:pid => [:pid]) when :purge_object repository.ingest :pid => [:pid], :file => [:foxml] when :set_datastream_options repository. when :modify_datastream repository.purge_object :pid => [:pid] rescue nil repository.ingest :pid => [:pid], :file => [:foxml] when :purge_datastream repository.purge_object :pid => [:pid] rescue nil repository.ingest :pid => [:pid], :file => [:foxml] end rescue # no-op end run_hook :after_rollback, :pid => [:pid], :method => method, :options => end end true end |
#with_transactions {|_self| ... } ⇒ Object
106 107 108 109 110 111 |
# File 'lib/rubydora/transactions.rb', line 106 def with_transactions(&block) old_state = Rubydora::Transactions.use_transactions Rubydora::Transactions.use_transactions = true yield(self) Rubydora::Transactions.use_transactions = old_state end |
#without_transactions {|_self| ... } ⇒ Object
113 114 115 116 117 118 |
# File 'lib/rubydora/transactions.rb', line 113 def without_transactions(&block) old_state = Rubydora::Transactions.use_transactions Rubydora::Transactions.use_transactions = false yield(self) Rubydora::Transactions.use_transactions = old_state end |