Class: Tuersteher::RolesSpecification

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#negationObject (readonly)

Returns the value of attribute negation.



444
445
446
# File 'lib/tuersteher.rb', line 444

def negation
  @negation
end

#rolesObject (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

Returns:

  • (Boolean)


451
452
453
454
455
456
457
# File 'lib/tuersteher.rb', line 451

def grant? path_or_model, method, 
  return false if .nil?
  # roles sind or verknüpft
  rc = @roles.any?{|role| .has_role?(role) }
  rc = !rc if @negation
  rc
end

#to_sObject



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