Class: Rubydora::Transaction
- Inherits:
-
Object
- Object
- Rubydora::Transaction
- 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.
88 89 90 91 |
# File 'lib/rubydora/transactions.rb', line 88 def initialize repository, &block @repository = repository with_transactions(&block) end |
Instance Attribute Details
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
87 88 89 |
# File 'lib/rubydora/transactions.rb', line 87 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.
114 115 116 117 118 119 120 121 122 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 |
# File 'lib/rubydora/transactions.rb', line 114 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 end end true end |
#with_transactions {|_self| ... } ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/rubydora/transactions.rb', line 93 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
102 103 104 105 106 107 108 109 |
# File 'lib/rubydora/transactions.rb', line 102 def without_transactions &block old_state = Rubydora::Transactions.use_transactions Rubydora::Transactions.use_transactions = false yield(self) Rubydora::Transactions.use_transactions = old_state end |