Class: Authorization::AuthorizationRule
- Inherits:
-
Object
- Object
- Authorization::AuthorizationRule
- Defined in:
- lib/declarative_authorization/authorization.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
-
#join_operator ⇒ Object
readonly
Returns the value of attribute join_operator.
-
#privileges ⇒ Object
readonly
Returns the value of attribute privileges.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
Instance Method Summary collapse
- #append_attribute(attribute) ⇒ Object
- #append_privileges(privs) ⇒ Object
-
#initialize(role, privileges = [], contexts = nil, join_operator = :or) ⇒ AuthorizationRule
constructor
A new instance of AuthorizationRule.
- #matches?(roles, privs, context = nil) ⇒ Boolean
- #to_long_s ⇒ Object
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
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
332 333 334 |
# File 'lib/declarative_authorization/authorization.rb', line 332 def attributes @attributes end |
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
332 333 334 |
# File 'lib/declarative_authorization/authorization.rb', line 332 def contexts @contexts end |
#join_operator ⇒ Object (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 |
#privileges ⇒ Object (readonly)
Returns the value of attribute privileges.
332 333 334 |
# File 'lib/declarative_authorization/authorization.rb', line 332 def privileges @privileges end |
#role ⇒ Object (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
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_s ⇒ Object
356 357 358 |
# File 'lib/declarative_authorization/authorization.rb', line 356 def to_long_s attributes.collect {|attr| attr.to_long_s } * "; " end |