Class: CanTango::Permits::RoleGroupPermit::Builder

Inherits:
CanTango::PermitEngine::Builder::Base show all
Includes:
Helpers::Debug
Defined in:
lib/cantango/permits/role_group_permit/builder.rb

Instance Attribute Summary

Attributes inherited from CanTango::PermitEngine::Builder::Base

#ability

Instance Method Summary collapse

Methods included from Helpers::Debug

#debug

Methods inherited from CanTango::PermitEngine::Builder::Base

#initialize

Constructor Details

This class inherits a constructor from CanTango::PermitEngine::Builder::Base

Instance Method Details

#buildArray<RoleGroupPermit::Base>

builds a list of Permits for each role group of the current ability user (or account)

Returns:

  • (Array<RoleGroupPermit::Base>)

    the role group permits built for this ability



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cantango/permits/role_group_permit/builder.rb', line 8

def build
  matching_permits = matching_role_groups(roles).inject([]) do |permits, role_group|
    debug "Building RoleGroupPermit for #{role_group}"
    (permits << create_permit(role_group)) if valid?(role_group)
    permits
  end.compact

  if matching_permits.empty?
    debug "Not building any RoleGroupPermits since no role groups could be found that are relevant for the permission candidate"
    return []
  end
  matching_permits
end

#filter(role_group) ⇒ Object



31
32
33
# File 'lib/cantango/permits/role_group_permit/builder.rb', line 31

def filter role_group
  CanTango::Filters::RoleGroupFilter.new role_group
end

#nameObject



22
23
24
# File 'lib/cantango/permits/role_group_permit/builder.rb', line 22

def name
  :role_group
end

#valid?(role_group) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/cantango/permits/role_group_permit/builder.rb', line 26

def valid? role_group
  return true if !role_groups_filter?
  filter(role_group).valid?
end