Module: Unconstrained::Handlers

Defined in:
lib/unconstrained/handlers.rb,
lib/unconstrained/handlers/postgresql.rb,
lib/unconstrained/handlers/abstract_handler.rb

Defined Under Namespace

Classes: AbstractHandler, PostgreSQLFKHandler

Class Method Summary collapse

Class Method Details

.handle(action, exception, record) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/unconstrained/handlers.rb', line 13

def handle(action, exception, record)
  h = handler(exception).new(exception.message, record)
  case action
  when :destroy
    h.handle_destroy
  when :save
    h.handle_save
  end
end

.handler(exception) ⇒ Object



9
10
11
# File 'lib/unconstrained/handlers.rb', line 9

def handler(exception)
  @handlers.detect { |k, _| exception.message.start_with?(k) }&.last
end

.register(exception_name, handler) ⇒ Object



5
6
7
# File 'lib/unconstrained/handlers.rb', line 5

def register(exception_name, handler)
  @handlers[exception_name] = handler
end