Class: Authorization::AuthorizationRule
- Inherits:
-
Object
- Object
- Authorization::AuthorizationRule
- Defined in:
- lib/authorization.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
-
#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) ⇒ AuthorizationRule
constructor
A new instance of AuthorizationRule.
- #matches?(roles, privs, context = nil) ⇒ Boolean
- #to_long_s ⇒ Object
Constructor Details
#initialize(role, privileges = [], contexts = nil) ⇒ AuthorizationRule
Returns a new instance of AuthorizationRule.
312 313 314 315 316 317 |
# File 'lib/authorization.rb', line 312 def initialize (role, privileges = [], contexts = nil) @role = role @privileges = Set.new(privileges) @contexts = Set.new((contexts && !contexts.is_a?(Array) ? [contexts] : contexts)) @attributes = [] end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
310 311 312 |
# File 'lib/authorization.rb', line 310 def attributes @attributes end |
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
310 311 312 |
# File 'lib/authorization.rb', line 310 def contexts @contexts end |
#privileges ⇒ Object (readonly)
Returns the value of attribute privileges.
310 311 312 |
# File 'lib/authorization.rb', line 310 def privileges @privileges end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
310 311 312 |
# File 'lib/authorization.rb', line 310 def role @role end |
Instance Method Details
#append_attribute(attribute) ⇒ Object
323 324 325 |
# File 'lib/authorization.rb', line 323 def append_attribute (attribute) @attributes << attribute end |
#append_privileges(privs) ⇒ Object
319 320 321 |
# File 'lib/authorization.rb', line 319 def append_privileges (privs) @privileges.merge(privs) end |
#matches?(roles, privs, context = nil) ⇒ Boolean
327 328 329 330 331 |
# File 'lib/authorization.rb', line 327 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
333 334 335 |
# File 'lib/authorization.rb', line 333 def to_long_s attributes.collect {|attr| attr.to_long_s } * "; " end |