lib/authorized_persona/authorization.rb
# Configure authorization for an authorized persona class
Configure authorization for an authorized persona class
Configure authorization for an authorized persona class
def authorize_persona(class_name:, current_user_method: nil) 
        raise AuthorizedPersona::Error, "you can only configure authorization once" if authorization_persona_class_name.present?
        raise AuthorizedPersona::Error, "class_name must be a string" unless class_name.is_a?(String)
        raise AuthorizedPersona::Error, "current_user_method must be a symbol" if current_user_method && !current_user_method.is_a?(Symbol)
        self.authorization_persona_class_name = class_name
        unless authorization_persona < AuthorizedPersona::Persona
          raise AuthorizedPersona::Error, "#{class_name} must be an AuthorizedPersona::Persona"
        end
        model_name = if authorization_persona.respond_to?(:model_name)
                       authorization_persona.model_name.singular_route_key
                     else
                       authorization_persona.name.underscore
                     end
        self.authorization_current_user_method = current_user_method || :"current_#{model_name}"
        before_action :authorize!
      end
def authorize_persona ( class_name : , current_user_method : nil ) raise AuthorizedPersona :: Error , "you can only configure authorization once" if authorization_persona_class_name . present? raise AuthorizedPersona :: Error , "class_name must be a string" unless class_name . is_a? ( String ) raise AuthorizedPersona :: Error , "current_user_method must be a symbol" if current_user_method && ! current_user_method . is_a? ( Symbol ) self . authorization_persona_class_name = class_name unless authorization_persona < AuthorizedPersona :: Persona raise AuthorizedPersona :: Error , "#{class_name} must be an AuthorizedPersona::Persona" end model_name = if authorization_persona . respond_to? ( :model_name ) authorization_persona . model_name . singular_route_key else authorization_persona . name . underscore end self . authorization_current_user_method = current_user_method || :" current_ #{ model_name } " before_action :authorize! end
Configure authorization for an authorized persona class
Configure authorization for an authorized persona class
# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/LineLength
class_name
<not_specific>
current_user_method
<not_specific>