Class: Casbin::Model::Assertion

Inherits:
Object
  • Object
show all
Defined in:
lib/casbin-ruby/model/assertion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/casbin-ruby/model/assertion.rb', line 8

def key
  @key
end

#loggerObject (readonly)

Returns the value of attribute logger.



9
10
11
# File 'lib/casbin-ruby/model/assertion.rb', line 9

def logger
  @logger
end

#policyObject

Returns the value of attribute policy.



8
9
10
# File 'lib/casbin-ruby/model/assertion.rb', line 8

def policy
  @policy
end

#rmObject

Returns the value of attribute rm.



8
9
10
# File 'lib/casbin-ruby/model/assertion.rb', line 8

def rm
  @rm
end

#tokensObject

Returns the value of attribute tokens.



8
9
10
# File 'lib/casbin-ruby/model/assertion.rb', line 8

def tokens
  @tokens
end

#valueObject

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



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