Class: Tuersteher::RolesSpecification
- Inherits:
-
Object
- Object
- Tuersteher::RolesSpecification
- Defined in:
- lib/tuersteher.rb
Instance Attribute Summary collapse
-
#negation ⇒ Object
readonly
Returns the value of attribute negation.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
Instance Method Summary collapse
- #grant?(path_or_model, method, login_ctx) ⇒ Boolean
-
#initialize(role, negation) ⇒ RolesSpecification
constructor
A new instance of RolesSpecification.
- #to_s ⇒ Object
Constructor Details
#initialize(role, negation) ⇒ RolesSpecification
Returns a new instance of RolesSpecification.
446 447 448 449 |
# File 'lib/tuersteher.rb', line 446 def initialize role, negation @negation = negation @roles = [role] end |
Instance Attribute Details
#negation ⇒ Object (readonly)
Returns the value of attribute negation.
444 445 446 |
# File 'lib/tuersteher.rb', line 444 def negation @negation end |
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
444 445 446 |
# File 'lib/tuersteher.rb', line 444 def roles @roles end |
Instance Method Details
#grant?(path_or_model, method, login_ctx) ⇒ Boolean
451 452 453 454 455 456 457 |
# File 'lib/tuersteher.rb', line 451 def grant? path_or_model, method, login_ctx return false if login_ctx.nil? # roles sind or verknüpft rc = @roles.any?{|role| login_ctx.has_role?(role) } rc = !rc if @negation rc end |
#to_s ⇒ Object
459 460 461 462 |
# File 'lib/tuersteher.rb', line 459 def to_s role_s = @roles.size == 1 ? "role(:#{@roles.first})" : "roles(#{@roles.map{|r| ":#{r}"}.join(',')})" "#{@negation && 'not.'}#{role_s}" end |