module Subroutine::Auth

Public Class Methods

new(*args, &block) click to toggle source
Calls superclass method
# File lib/subroutine/auth.rb, line 85
def initialize(*args, &block)
  raise Subroutine::Auth::AuthorizationNotDeclaredError unless self.class.authorization_declared

  @skip_auth_checks = false

  inputs = case args.last
  when *::Subroutine::Fields.allowed_input_classes
    args.pop
  else
    {}
  end

  super(inputs, &block)

  user = args.shift

  unless self.class.supported_user_class_names.include?(user.class.name)
    raise ArgumentError, "current_user must be one of the following types {#{self.class.supported_user_class_names.join(",")}} but was #{user.class.name}"
  end

  @current_user = user
end

Public Instance Methods

current_user() click to toggle source
# File lib/subroutine/auth.rb, line 117
def current_user
  @current_user = user_class_name.constantize.find(@current_user) if ::Integer === @current_user
  @current_user
end
skip_auth_checks!() click to toggle source
# File lib/subroutine/auth.rb, line 108
def skip_auth_checks!
  @skip_auth_checks = true
  self
end
skip_auth_checks?() click to toggle source
# File lib/subroutine/auth.rb, line 113
def skip_auth_checks?
  !!@skip_auth_checks
end
unauthorized!(reason = nil) click to toggle source
# File lib/subroutine/auth.rb, line 122
def unauthorized!(reason = nil)
  reason ||= :unauthorized
  raise ::Subroutine::Auth::NotAuthorizedError, reason
end