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.
301 302 303 |
# File 'backend/app/model/db.rb', line 301 def initialize(happy_path) @happy_path = happy_path end |
Instance Method Details
#and_if_constraint_fails(&failed_path) ⇒ Object
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'backend/app/model/db.rb', line 306 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 |