Module: Guarda::Authorization
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/guarda/authorization.rb
Defined Under Namespace
Classes: AuthorizationNotPerformedError, NotAuthorizedError
Instance Method Summary
collapse
Instance Method Details
#authorize(record = nil, controller: nil, query: nil) ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/guarda/authorization.rb', line 13
def authorize(record = nil, controller: nil, query: nil)
@_authorization_performed = true
controller ||= controller_path
query ||= "#{action_name}?"
policy(controller, record).public_send(query) ||
raise(NotAuthorizedError, self.class)
end
|
#policy(controller, record = nil) ⇒ Object
22
23
24
|
# File 'lib/guarda/authorization.rb', line 22
def policy(controller, record = nil)
PolicyFinder.find(controller).new(record)
end
|
26
27
28
29
|
# File 'lib/guarda/authorization.rb', line 26
def verify_authorization_performed
authorization_performed? ||
raise(AuthorizationNotPerformedError, self.class)
end
|