Module: Miau

Extended by:
ActiveSupport::Concern
Defined in:
lib/miau.rb,
lib/miau/error.rb,
lib/miau/storage.rb,
lib/miau/version.rb

Defined Under Namespace

Classes: AuthorizationNotPerformedError, Error, NotAuthorizedError, NotDefinedError, PolicyStorage

Constant Summary collapse

VERSION =

2023-12-13

"1.0.3"

Instance Method Summary collapse

Instance Method Details

#authorize!(resource = nil, hsh = {}) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/miau.rb', line 19

def authorize!(resource = nil, hsh = {})
  @_miau_authorization_performed = true
  return true if authorized?(resource, hsh)

  klass, action = klass_action(hsh)
  msg = "class <#{klass} action <#{action}>"
  raise Miau::NotAuthorizedError, msg
end

#authorized?(resource = nil, hsh = {}) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/miau.rb', line 28

def authorized?(resource = nil, hsh = {})
  klass, action = klass_action(hsh)
  Miau::PolicyStorage.instance.run(klass, action, miau_user, resource)
end

#miau_authorization_performed?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/miau.rb', line 45

def miau_authorization_performed?
  !!@_miau_authorization_performed
end

#miau_userObject



33
34
35
# File 'lib/miau.rb', line 33

def miau_user
  current_user
end

#skip_authorizationObject



37
38
39
# File 'lib/miau.rb', line 37

def skip_authorization
  @_miau_authorization_performed = true
end

#verify_authorizedObject



41
42
43
# File 'lib/miau.rb', line 41

def verify_authorized
  raise AuthorizationNotPerformedError unless miau_authorization_performed?
end