Class: Ingress::Permissions

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Permissions

Returns a new instance of Permissions.



41
42
43
# File 'lib/ingress/permissions.rb', line 41

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



39
40
41
# File 'lib/ingress/permissions.rb', line 39

def user
  @user
end

Class Method Details

.define_role_permissions(role_identifier = nil, permissions_class = nil, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ingress/permissions.rb', line 22

def define_role_permissions(role_identifier = nil, permissions_class = nil, &block)
  if role_identifier.nil?
    role_identifier = :dummy
  end

  if permissions_class
    @permissions_repository = permissions_repository.merge(
      Services::CopyPermissionsRepositoryIntoRole.perform(role_identifier, permissions_class.permissions_repository),
    )
  end

  if block_given?
    @permissions_repository = permissions_repository.merge(Services::BuildPermissionsRepositoryForRole.perform(role_identifier, &block))
  end
end

.inherits(permissions_class) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/ingress/permissions.rb', line 12

def inherits(permissions_class)
  role_identifier = :dummy

  if permissions_class
    @permissions_repository = permissions_repository.merge(
      Services::CopyPermissionsRepositoryIntoRole.perform(role_identifier, permissions_class.permissions_repository),
    )
  end
end

.permissions_repositoryObject



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

def permissions_repository
  @permissions_repository ||= PermissionsRepository.new
end

Instance Method Details

#can?(action, subject) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
# File 'lib/ingress/permissions.rb', line 45

def can?(action, subject)
  find_matching_rules(action, subject).any? do |rule|
    rule.match?(action, subject, user)
  end
end

#user_role_identifiersObject



51
52
53
# File 'lib/ingress/permissions.rb', line 51

def user_role_identifiers
  []
end