Class: CanTango::Builder::Permit::RoleGroup

Inherits:
Base
  • Object
show all
Includes:
Helpers::Debug
Defined in:
lib/cantango/roles_ext/builder/permit/role_group.rb

Instance Method Summary collapse

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



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cantango/roles_ext/builder/permit/role_group.rb', line 7

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



30
31
32
# File 'lib/cantango/roles_ext/builder/permit/role_group.rb', line 30

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

#nameObject



21
22
23
# File 'lib/cantango/roles_ext/builder/permit/role_group.rb', line 21

def name
  :role_group
end

#valid?(role_group) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/cantango/roles_ext/builder/permit/role_group.rb', line 25

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