module Strongbolt::BoltedController

Constants

ACTIONS_MAPPING

Maps controller actions to CRUD operations

Public Class Methods

included(receiver) click to toggle source
# File lib/strongbolt/bolted_controller.rb, line 257
def self.included(receiver)
  receiver.class_eval do
    # Compulsory filters
    before_action :set_current_user
    after_action :unset_current_user

    # Catch Grant error
    around_action :catch_grant_error

    # Quick check of high level authorization
    before_action :check_authorization

    # A list storing actions that render without authorization
    self.class.send :attr_accessor, :actions_without_authorization

    # To allow render without authorization
    alias_method :_render, :render

    # Catch errors
    rescue_from Strongbolt::Unauthorized, Grant::Error do |e|
      if respond_to? :unauthorized
        unauthorized e
      else
        raise Strongbolt::Unauthorized, e.to_s
      end
    end
  end # End receiver class eval

  receiver.extend         ClassMethods
  receiver.send :include, InstanceMethods
end