Class: Authorization::AuthorizationRuleSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/declarative_authorization/authorization.rb

Instance Method Summary collapse

Constructor Details

#initialize(rules = []) ⇒ AuthorizationRuleSet

Returns a new instance of AuthorizationRuleSet



369
370
371
372
# File 'lib/declarative_authorization/authorization.rb', line 369

def initialize (rules = [])
  @rules = rules.clone
  reset!
end

Instance Method Details

#<<(rule) ⇒ Object



390
391
392
393
# File 'lib/declarative_authorization/authorization.rb', line 390

def << rule
  @rules << rule
  reset!
end

#delete(rule) ⇒ Object



386
387
388
389
# File 'lib/declarative_authorization/authorization.rb', line 386

def delete rule
  @rules.delete rule
  reset!
end

#each(&block) ⇒ Object



394
395
396
# File 'lib/declarative_authorization/authorization.rb', line 394

def each &block
  @rules.each &block
end

#initialize_copy(source) ⇒ Object



374
375
376
377
# File 'lib/declarative_authorization/authorization.rb', line 374

def initialize_copy (source)
  @rules = @rules.collect {|rule| rule.clone}
  reset!
end

#matching(roles, privileges, context) ⇒ Object



379
380
381
382
383
384
385
# File 'lib/declarative_authorization/authorization.rb', line 379

def matching(roles, privileges, context)
  roles = [roles] unless roles.is_a?(Array)
  rules = cached_auth_rules[context] || []
  rules.select do |rule|
    rule.matches? roles, privileges, context
  end
end