Class: ContextRole

Inherits:
Object
  • Object
show all
Defined in:
lib/cbac/context_role.rb

Overview

ContextRole is the class containing the context role definitions

Usage: ContextRole.add :logged_in_user, “!session.nil?”

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.rolesObject (readonly)

Hash containing all the context roles. Keys are the role names Values are the Ruby eval strings Eval strings must result in true or false



8
9
10
# File 'lib/cbac/context_role.rb', line 8

def roles
  @roles
end

Class Method Details

.add(symbol, context_rule = "", &block) ⇒ Object

Adds a context role to the list of context roles. @symbol defines the name of the context role @context_rule defines the ruby code to be evaluated when determining role membership

If the context role already exists, an exception is thrown.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
# File 'lib/cbac/context_role.rb', line 15

def add(symbol, context_rule = "", &block)
  symbol = symbol.to_sym
  @roles = Hash.new if @roles.nil?
  raise ArgumentError, "CBAC: ContextRole was already defined:" + symbol.to_s if @roles.keys.include?(symbol)
  # TODO following code
  #raise ArgumentError, "CBAC: cannot specify both string rule and block rule" unless context_rule.nil? and block.nil?
  # TODO context parameter in block statement is not explicitly tested
  block = eval("Proc.new {|context| " + context_rule + "}") if block.nil?
  @roles[symbol] = block
end