Module: Subroutine::Auth
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/subroutine/auth.rb,
lib/subroutine/auth/not_authorized_error.rb,
lib/subroutine/auth/authorization_not_declared_error.rb
Defined Under Namespace
Modules: ClassMethods
Classes: AuthorizationNotDeclaredError, NotAuthorizedError
Instance Method Summary
collapse
Instance Method Details
#current_user ⇒ Object
117
118
119
120
|
# 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
|
#initialize(*args, &block) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# 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
|
#skip_auth_checks! ⇒ Object
108
109
110
111
|
# File 'lib/subroutine/auth.rb', line 108
def skip_auth_checks!
@skip_auth_checks = true
self
end
|
#skip_auth_checks? ⇒ Boolean
113
114
115
|
# File 'lib/subroutine/auth.rb', line 113
def skip_auth_checks?
!!@skip_auth_checks
end
|
#unauthorized!(reason = nil) ⇒ Object
122
123
124
125
|
# File 'lib/subroutine/auth.rb', line 122
def unauthorized!(reason = nil)
reason ||= :unauthorized
raise ::Subroutine::Auth::NotAuthorizedError, reason
end
|