Class: Ingress::PermissionsDsl

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role_identifier) ⇒ PermissionsDsl

Returns a new instance of PermissionsDsl.



7
8
9
10
# File 'lib/ingress/permissions_dsl.rb', line 7

def initialize(role_identifier)
  @role_identifier = role_identifier
  @permission_repository = PermissionsRepository.new
end

Instance Attribute Details

#permission_repositoryObject (readonly)

Returns the value of attribute permission_repository.



5
6
7
# File 'lib/ingress/permissions_dsl.rb', line 5

def permission_repository
  @permission_repository
end

#role_identifierObject (readonly)

Returns the value of attribute role_identifier.



5
6
7
# File 'lib/ingress/permissions_dsl.rb', line 5

def role_identifier
  @role_identifier
end

Instance Method Details

#can(actions, subjects, options = {}, &block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/ingress/permissions_dsl.rb', line 16

def can(actions, subjects, options = {}, &block)
  for_each_action_and_subject(actions, subjects) do |action, subject|
    conditions = conditions_from(options, block)

    permission_repository.add_permission(role_identifier, true, action, subject, conditions)
  end
end

#can_do_anythingObject



12
13
14
# File 'lib/ingress/permissions_dsl.rb', line 12

def can_do_anything
  permission_repository.add_permission(role_identifier, true, "*", "*")
end

#cannot(actions, subjects, options = {}, &block) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/ingress/permissions_dsl.rb', line 24

def cannot(actions, subjects, options = {}, &block)
  for_each_action_and_subject(actions, subjects) do |action, subject|
    conditions = conditions_from(options, block)

    permission_repository.add_permission(role_identifier, false, action, subject, conditions)
  end
end