Class: DB::DBAttempt
- Inherits:
-
Object
- Object
- DB::DBAttempt
- Defined in:
- backend/app/model/db.rb
Instance Method Summary (collapse)
-
- (Object) and_if_constraint_fails(&failed_path)
-
- (DBAttempt) initialize(happy_path)
constructor
A new instance of DBAttempt.
Constructor Details
- (DBAttempt) initialize(happy_path)
Returns a new instance of DBAttempt
194 195 196 |
# File 'backend/app/model/db.rb', line 194 def initialize(happy_path) @happy_path = happy_path end |
Instance Method Details
- (Object) and_if_constraint_fails(&failed_path)
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'backend/app/model/db.rb', line 199 def and_if_constraint_fails(&failed_path) begin DB.transaction(:savepoint => DB.needs_savepoint?) do @happy_path.call end rescue Sequel::DatabaseError => ex if DB.is_integrity_violation(ex) failed_path.call(ex) else raise ex end rescue Sequel::ValidationFailed => ex failed_path.call(ex) end end |