module Rodauth::Rails::Feature::Callbacks

Private Instance Methods

_around_rodauth() click to toggle source
Calls superclass method
# File lib/rodauth/rails/feature/callbacks.rb, line 7
def _around_rodauth
  rails_controller_around { super }
end
handle_rails_controller_response(result) click to toggle source

Handles controller rendering a response or setting response headers.

# File lib/rodauth/rails/feature/callbacks.rb, line 43
def handle_rails_controller_response(result)
  if rails_controller_instance.performed?
    rails_controller_response
  elsif result
    result[1].merge!(rails_controller_instance.response.headers)
    result
  end
end
rails_controller_around() { || ... } click to toggle source

Runs controller callbacks and rescue handlers around Rodauth actions.

# File lib/rodauth/rails/feature/callbacks.rb, line 12
def rails_controller_around
  result = nil

  rails_controller_rescue do
    rails_controller_callbacks do
      result = catch(:halt) { yield }
    end
  end

  result = handle_rails_controller_response(result)

  throw :halt, result if result
end
rails_controller_callbacks(&block) click to toggle source

Runs any #(before|around|after)_action controller callbacks.

# File lib/rodauth/rails/feature/callbacks.rb, line 27
def rails_controller_callbacks(&block)
  rails_controller_instance.run_callbacks(:process_action, &block)
end
rails_controller_rescue() { || ... } click to toggle source

Runs any registered rescue_from controller handlers.

# File lib/rodauth/rails/feature/callbacks.rb, line 32
def rails_controller_rescue
  yield
rescue Exception => exception
  rails_controller_instance.rescue_with_handler(exception) || raise

  unless rails_controller_instance.performed?
    raise Rodauth::Rails::Error, "rescue_from handler didn't write any response"
  end
end
rails_controller_response() click to toggle source

Returns Roda response from controller response if set.

# File lib/rodauth/rails/feature/callbacks.rb, line 53
def rails_controller_response
  controller_response = rails_controller_instance.response

  response.status = controller_response.status
  response.headers.merge! controller_response.headers
  response.write controller_response.body

  response.finish
end