lib/rails_devs_for_data_integrity.rb
# Executes the block and traps data integrity violations
# Populates the +record+ errors objects with an appropriate message if such violation occurs
#
# ===Example
#  def save_safe
#   execute_with_data_integrity_check(self) { save }
#  end
Executes the block and traps data integrity violations
Populates the +record+ errors objects with an appropriate message if such violation occurs

Example
def save_safe
execute_with_data_integrity_check(self) { save }
end
Executes the block and traps data integrity violations Populates the + record + errors objects with an appropriate message if such violation occurs Example def save_safe execute_with_data_integrity_check ( self ) { save } end
def execute_with_data_integrity_check(record = nil, &block)
    @duplicate_exception = nil
    @foreign_key_exception = nil
    yield record
    true
  rescue ActiveRecord::StatementInvalid => exception
    handle_data_integrity_error(exception, record)
    return false
  end
def execute_with_data_integrity_check ( record = nil , & block ) @duplicate_exception = nil @foreign_key_exception = nil yield record true rescue ActiveRecord :: StatementInvalid => exception handle_data_integrity_error ( exception , record ) return false end
Executes the block and traps data integrity violations
Populates the +record+ errors objects with an appropriate message if such violation occurs
Executes the block and traps data integrity violations Populates the + record + errors objects with an appropriate message if such violation occurs
record
block