Class: Casbin::Model::Assertion
- Inherits:
-
Object
- Object
- Casbin::Model::Assertion
- Defined in:
- lib/casbin-ruby/model/assertion.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#policy ⇒ Object
Returns the value of attribute policy.
-
#rm ⇒ Object
Returns the value of attribute rm.
-
#tokens ⇒ Object
Returns the value of attribute tokens.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #build_role_links(rm) ⇒ Object
-
#initialize(hash = {}) ⇒ Assertion
constructor
A new instance of Assertion.
Constructor Details
#initialize(hash = {}) ⇒ Assertion
11 12 13 14 15 16 17 |
# File 'lib/casbin-ruby/model/assertion.rb', line 11 def initialize(hash = {}) @key = hash[:key].to_s @value = hash[:value].to_s @tokens = [*hash[:tokens]] @policy = [*hash[:policy]] @logger = hash[:logger] || Logger.new($stdout) end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/casbin-ruby/model/assertion.rb', line 8 def key @key end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/casbin-ruby/model/assertion.rb', line 9 def logger @logger end |
#policy ⇒ Object
Returns the value of attribute policy.
8 9 10 |
# File 'lib/casbin-ruby/model/assertion.rb', line 8 def policy @policy end |
#rm ⇒ Object
Returns the value of attribute rm.
8 9 10 |
# File 'lib/casbin-ruby/model/assertion.rb', line 8 def rm @rm end |
#tokens ⇒ Object
Returns the value of attribute tokens.
8 9 10 |
# File 'lib/casbin-ruby/model/assertion.rb', line 8 def tokens @tokens end |
#value ⇒ Object
Returns the value of attribute value.
8 9 10 |
# File 'lib/casbin-ruby/model/assertion.rb', line 8 def value @value end |
Instance Method Details
#build_role_links(rm) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/casbin-ruby/model/assertion.rb', line 19 def build_role_links(rm) @rm = rm count = value.count('_') policy.each do |rule| raise 'the number of "_" in role definition should be at least 2' if count < 2 raise 'grouping policy elements do not meet role definition' if rule.size < count rm.add_link(*rule) logger.info("Role links for: #{key}") rm.print_roles end end |