Module: Roleback
- Defined in:
- lib/roleback.rb,
lib/roleback/rule.rb,
lib/roleback/outcome.rb,
lib/roleback/version.rb,
lib/roleback/rule_book.rb,
lib/roleback/configuration.rb,
lib/roleback/user_extension.rb,
lib/roleback/definitions/role.rb,
lib/roleback/definitions/scope.rb,
lib/roleback/definitions/resource.rb,
lib/roleback/definitions/rule_based.rb
Defined Under Namespace
Modules: Definitions
Classes: Allow, Any, BadConfiguration, BadMatch, Configuration, Deny, Error, InvalidOrMisconfiguredUserClass, MissingRole, NotConfiguredError, OutcomeBase, Rule, RuleBook, UserExtension
Constant Summary
collapse
- ANY =
Any.new
- ALLOW =
Allow.new
- DENY =
Deny.new
- VERSION =
"0.2.0".freeze
Class Method Summary
collapse
Class Method Details
.allow ⇒ Object
29
30
31
|
# File 'lib/roleback/configuration.rb', line 29
def self.allow
::Roleback::ALLOW
end
|
.any ⇒ Object
25
26
27
|
# File 'lib/roleback/configuration.rb', line 25
def self.any
::Roleback::ANY
end
|
.can?(role_name, resource: ::Roleback.any, scope: ::Roleback.any, action: ::Roleback.any) ⇒ Boolean
45
46
47
48
49
50
51
|
# File 'lib/roleback/configuration.rb', line 45
def self.can?(role_name, resource: ::Roleback.any, scope: ::Roleback.any, action: ::Roleback.any)
role = self.configuration.find_role!(role_name)
return true if role.rules.can?(resource: resource, scope: scope, action: action)
false
end
|
.clear! ⇒ Object
37
38
39
|
# File 'lib/roleback/configuration.rb', line 37
def self.clear!
@config = nil
end
|
.configuration ⇒ Object
21
22
23
|
# File 'lib/roleback/configuration.rb', line 21
def self.configuration
@config || (raise ::Roleback::NotConfiguredError)
end
|
.define(options = {}, &block) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/roleback/configuration.rb', line 2
def self.define(options = {}, &block)
@config = ::Roleback::Configuration::Builder.new(options, &block).build if block_given?
@config.construct!
if options[:user_class]
@user_class = options[:user_class]
elsif defined?(::User)
@user_class = ::User
else
@user_class = nil
end
::Roleback::UserExtension.extend!(@user_class) if @user_class
@config
end
|
.deny ⇒ Object
33
34
35
|
# File 'lib/roleback/configuration.rb', line 33
def self.deny
::Roleback::DENY
end
|
.roles ⇒ Object
41
42
43
|
# File 'lib/roleback/configuration.rb', line 41
def self.roles
self.configuration.roles
end
|