Class: DB::DBPool::DBAttempt
- Inherits:
-
Object
- Object
- DB::DBPool::DBAttempt
- Defined in:
- backend/app/model/db.rb
Instance Method Summary collapse
-
#and_if_constraint_fails(&failed_path) ⇒ Object
-
#initialize(happy_path) ⇒ DBAttempt
constructor
A new instance of DBAttempt.
Constructor Details
#initialize(happy_path) ⇒ DBAttempt
Returns a new instance of DBAttempt.
292 293 294 |
# File 'backend/app/model/db.rb', line 292 def initialize(happy_path) @happy_path = happy_path end |
Instance Method Details
#and_if_constraint_fails(&failed_path) ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'backend/app/model/db.rb', line 297 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 |