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

Inherits:
CanTango::PermitEngine::Builder::Base show all
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 inherited from CanTango::PermitEngine::Builder::Base

#initialize

Methods included from Helpers::Debug

#debug

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



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

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

  if matching_permits.empty?
    puts "Not building any RoleGroupPermits since no role groups are roles that are members of a role group could be found for the permission candidate" if CanTango.debug?
    return []
  end
end

#filter(role_group) ⇒ Object



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

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

#nameObject



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

def name
  :role_group
end

#valid?(role_group) ⇒ Boolean

Returns:

  • (Boolean)


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

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