Module: CredentialAuthorization
- Defined in:
- lib/credential_authorization.rb,
lib/credential_authorization/errors.rb,
lib/credential_authorization/version.rb
Defined Under Namespace
Classes: InsufficientPermission, InvalidPermission, PermissionNotFound, SufficientPermission
Constant Summary
collapse
- VERSION =
"0.1.3"
Class Method Summary
collapse
Class Method Details
.build_permission_key(record:, permission:) ⇒ Object
39
40
41
|
# File 'lib/credential_authorization.rb', line 39
def self.build_permission_key(record:, permission:)
"#{record.class.name.downcase}.#{record.id}.#{permission}"
end
|
.can!(record:, permission:, &block) ⇒ Object
.can?(record:, permission:) ⇒ Boolean
15
16
17
18
19
20
|
# File 'lib/credential_authorization.rb', line 15
def self.can?(record:, permission:)
found = self.find_permission(self.build_permission_key(record:, permission:))
yield if block_given? && found
found
end
|
.cannot!(record:, permission:, &block) ⇒ Object
34
35
36
37
|
# File 'lib/credential_authorization.rb', line 34
def self.cannot!(record:, permission:, &block)
raise CredentialAuthorization::SufficientPermission.new(permission) unless self.cannot?(record:, permission:, &block)
true
end
|
.cannot?(record:, permission:) ⇒ Boolean
27
28
29
30
31
32
|
# File 'lib/credential_authorization.rb', line 27
def self.cannot?(record:, permission:)
found = self.find_permission(self.build_permission_key(record:, permission:))
yield if block_given? && !found
!found
end
|
11
12
13
|
# File 'lib/credential_authorization.rb', line 11
def self.configure(&block)
yield self
end
|