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.
104 105 106 107 |
# File 'lib/rubydora/transactions.rb', line 104 def initialize repository, &block @repository = repository with_transactions(&block) end |
Instance Attribute Details
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
100 101 102 |
# File 'lib/rubydora/transactions.rb', line 100 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.
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 167 168 169 170 171 172 173 174 |
# File 'lib/rubydora/transactions.rb', line 130 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
109 110 111 112 113 114 115 116 |
# File 'lib/rubydora/transactions.rb', line 109 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
118 119 120 121 122 123 124 125 |
# File 'lib/rubydora/transactions.rb', line 118 def without_transactions &block old_state = Rubydora::Transactions.use_transactions Rubydora::Transactions.use_transactions = false yield(self) Rubydora::Transactions.use_transactions = old_state end |