Class: AnnotationSecurity::RuleSet
- Defined in:
- lib/annotation_security/policy/rule_set.rb
Overview
AnnotationSecurity::RuleSet
Contains all rule objects for a policy
Instance Method Summary collapse
-
#add_rule(symbol, *args, &block) ⇒ Object
Adds a new rule to this rule set.
-
#copy_rule_from(symbol, source, static) ⇒ Object
Copies a rule from another rule set.
-
#create_dynamic_copy(symbol) ⇒ Object
Creates a dynamic rule that redirects to a static rule with the same name.
-
#get_dynamic_rule(symbol) ⇒ Object
Returns a dynamic rule or nil if the rule does not exist.
-
#get_rule(symbol, static) ⇒ Object
Returns a rule object or nil if the rule does not exist.
-
#get_static_rule(symbol) ⇒ Object
Returns a static rule or nil if the rule does not exist.
-
#initialize(pclass) ⇒ RuleSet
constructor
Initializes the rule set *
pclass
Policy class this rule set belongs to. - #to_s ⇒ Object
Constructor Details
#initialize(pclass) ⇒ RuleSet
Initializes the rule set
-
pclass
Policy class this rule set belongs to
13 14 15 16 17 18 19 |
# File 'lib/annotation_security/policy/rule_set.rb', line 13 def initialize(pclass) super() @pclass = pclass @rights = {} @static = {} @dynamic = {} end |
Instance Method Details
#add_rule(symbol, *args, &block) ⇒ Object
Adds a new rule to this rule set. The rule will be classified either as dynamic, static, both or right. Returns the newly create rule. For an explainition of the parameters see AnnotationSecurity::Rule#initialize.
72 73 74 |
# File 'lib/annotation_security/policy/rule_set.rb', line 72 def add_rule(symbol,*args,&block) __add__ AnnotationSecurity::Rule.new(symbol,@pclass,*args,&block) end |
#copy_rule_from(symbol, source, static) ⇒ Object
Copies a rule from another rule set. Returns the newly created rule or nil if the operation had no effect.
-
symbol
name of the rule -
source
rule set to copy from -
static
boolean specifing whether the rule is static or dynamic
51 52 53 |
# File 'lib/annotation_security/policy/rule_set.rb', line 51 def copy_rule_from(symbol,source,static) add_copy(source.get_rule(symbol,static)) end |
#create_dynamic_copy(symbol) ⇒ Object
Creates a dynamic rule that redirects to a static rule with the same name. Returns the newly created rule or nil if the operation had no effect.
-
symbol
name of the rule
58 59 60 61 62 63 64 65 66 |
# File 'lib/annotation_security/policy/rule_set.rb', line 58 def create_dynamic_copy(symbol) rule = get_static_rule(symbol) if rule add_rule(symbol, "static_policy.#{symbol}(*args)", :resource, :require_credential => rule.requires_credential?) end end |
#get_dynamic_rule(symbol) ⇒ Object
Returns a dynamic rule or nil if the rule does not exist.
-
symbol
name of the rule
34 35 36 37 |
# File 'lib/annotation_security/policy/rule_set.rb', line 34 def get_dynamic_rule(symbol) # If no rule is available, maybe there is a right that can be used @dynamic[symbol] ||= get_dynamic_right(symbol) end |
#get_rule(symbol, static) ⇒ Object
Returns a rule object or nil if the rule does not exist.
-
symbol
name of the rule -
static
boolean specifing whether the rule is static or dynamic
28 29 30 |
# File 'lib/annotation_security/policy/rule_set.rb', line 28 def get_rule(symbol,static) static ? get_static_rule(symbol) : get_dynamic_rule(symbol) end |
#get_static_rule(symbol) ⇒ Object
Returns a static rule or nil if the rule does not exist.
-
symbol
name of the rule
41 42 43 44 |
# File 'lib/annotation_security/policy/rule_set.rb', line 41 def get_static_rule(symbol) # If no rule is available, maybe there is a right that can be used @static[symbol] ||= get_static_right(symbol) end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/annotation_security/policy/rule_set.rb', line 21 def to_s "<RuleSet of #@pclass>" end |