Class: Authorization::AuthorizationRule

Inherits:
Object
  • Object
show all
Defined in:
lib/declarative_authorization/authorization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role, privileges = [], contexts = nil, join_operator = :or) ⇒ AuthorizationRule

Returns a new instance of AuthorizationRule.



334
335
336
337
338
339
340
# File 'lib/declarative_authorization/authorization.rb', line 334

def initialize (role, privileges = [], contexts = nil, join_operator = :or)
  @role = role
  @privileges = Set.new(privileges)
  @contexts = Set.new((contexts && !contexts.is_a?(Array) ? [contexts] : contexts))
  @join_operator = join_operator
  @attributes = []
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



332
333
334
# File 'lib/declarative_authorization/authorization.rb', line 332

def attributes
  @attributes
end

#contextsObject (readonly)

Returns the value of attribute contexts.



332
333
334
# File 'lib/declarative_authorization/authorization.rb', line 332

def contexts
  @contexts
end

#join_operatorObject (readonly)

Returns the value of attribute join_operator.



332
333
334
# File 'lib/declarative_authorization/authorization.rb', line 332

def join_operator
  @join_operator
end

#privilegesObject (readonly)

Returns the value of attribute privileges.



332
333
334
# File 'lib/declarative_authorization/authorization.rb', line 332

def privileges
  @privileges
end

#roleObject (readonly)

Returns the value of attribute role.



332
333
334
# File 'lib/declarative_authorization/authorization.rb', line 332

def role
  @role
end

Instance Method Details

#append_attribute(attribute) ⇒ Object



346
347
348
# File 'lib/declarative_authorization/authorization.rb', line 346

def append_attribute (attribute)
  @attributes << attribute
end

#append_privileges(privs) ⇒ Object



342
343
344
# File 'lib/declarative_authorization/authorization.rb', line 342

def append_privileges (privs)
  @privileges.merge(privs)
end

#matches?(roles, privs, context = nil) ⇒ Boolean

Returns:

  • (Boolean)


350
351
352
353
354
# File 'lib/declarative_authorization/authorization.rb', line 350

def matches? (roles, privs, context = nil)
  roles = [roles] unless roles.is_a?(Array)
  @contexts.include?(context) and roles.include?(@role) and 
    not (@privileges & privs).empty?
end

#to_long_sObject



356
357
358
# File 'lib/declarative_authorization/authorization.rb', line 356

def to_long_s
  attributes.collect {|attr| attr.to_long_s } * "; "
end