Class: RescueUniqueConstraint::RescueHandler
- Inherits:
-
Object
- Object
- RescueUniqueConstraint::RescueHandler
- Defined in:
- lib/rescue_unique_constraint/rescue_handler.rb
Overview
Handles storing and matching [index, field] pairs to exceptions
Instance Method Summary collapse
- #add_index(index, field, scope) ⇒ Object
-
#initialize(model) ⇒ RescueHandler
constructor
A new instance of RescueHandler.
- #matching_indexes(e) ⇒ Object
Constructor Details
#initialize(model) ⇒ RescueHandler
Returns a new instance of RescueHandler.
4 5 6 7 |
# File 'lib/rescue_unique_constraint/rescue_handler.rb', line 4 def initialize(model) @model = model @indexes_to_rescue_on = [] end |
Instance Method Details
#add_index(index, field, scope) ⇒ Object
9 10 11 |
# File 'lib/rescue_unique_constraint/rescue_handler.rb', line 9 def add_index(index, field, scope) indexes_to_rescue_on << Index.new(index, field, scope) end |
#matching_indexes(e) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/rescue_unique_constraint/rescue_handler.rb', line 13 def matching_indexes(e) indexes = indexes_to_rescue_on.select do |index| database_adapter.index_error?(index, e.) end raise e unless indexes.any? indexes end |