Class: Micro::Authorization::Permissions::Model
- Inherits:
-
Object
- Object
- Micro::Authorization::Permissions::Model
- Defined in:
- lib/micro/authorization/permissions/model.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
Instance Method Summary collapse
-
#initialize(role, context:) ⇒ Model
constructor
A new instance of Model.
- #to(features) ⇒ Object
- #to?(features = nil) ⇒ Boolean
- #to_not?(features = nil) ⇒ Boolean
Constructor Details
#initialize(role, context:) ⇒ Model
Returns a new instance of Model.
7 8 9 10 11 |
# File 'lib/micro/authorization/permissions/model.rb', line 7 def initialize(role, context:) @role = role.dup.freeze @cache = {} @context = Utils.values_as_downcased_strings(context).freeze end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/micro/authorization/permissions/model.rb', line 5 def context @context end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
5 6 7 |
# File 'lib/micro/authorization/permissions/model.rb', line 5 def role @role end |
Instance Method Details
#to(features) ⇒ Object
13 14 15 |
# File 'lib/micro/authorization/permissions/model.rb', line 13 def to(features) Permissions::Checker.new(@role, features) end |
#to?(features = nil) ⇒ Boolean
17 18 19 20 21 22 23 24 25 |
# File 'lib/micro/authorization/permissions/model.rb', line 17 def to?(features = nil) = to(features) cache_key = .required_features.inspect return @cache[cache_key] unless @cache[cache_key].nil? @cache[cache_key] = .context?(@context) end |
#to_not?(features = nil) ⇒ Boolean
27 28 29 |
# File 'lib/micro/authorization/permissions/model.rb', line 27 def to_not?(features = nil) !to?(features) end |