Class: CanTango::Permits::RoleGroupPermit

Inherits:
CanTango::Permit
  • Object
show all
Extended by:
Helpers::RoleMethods
Includes:
Helpers::RoleMethods
Defined in:
lib/cantango/permits/role_group_permit.rb,
lib/cantango/permits/role_group_permit/finder.rb,
lib/cantango/permits/role_group_permit/builder.rb

Defined Under Namespace

Classes: Builder, Finder

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::RoleMethods

config, has_role_group_meth, has_role_meth, role_groups_list_meth, roles_list_meth

Constructor Details

#initialize(ability) ⇒ RoleGroupPermit

creates the permit



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

def initialize ability
  super
end

Class Method Details

.hash_keyObject



53
54
55
# File 'lib/cantango/permits/role_group_permit.rb', line 53

def self.hash_key
  role_groups_list_meth
end

.inherited(base_clazz) ⇒ Object



7
8
9
# File 'lib/cantango/permits/role_group_permit.rb', line 7

def self.inherited(base_clazz)
  CanTango.config.permits.register_permit_class role_group_name(base_clazz), base_clazz, type, (base_clazz)
end

.role_group_name(clazz) ⇒ Object



15
16
17
# File 'lib/cantango/permits/role_group_permit.rb', line 15

def self.role_group_name clazz
  clazz.name.demodulize.gsub(/(.*)(RoleGroupPermit)/, '\1').underscore.to_sym
end

.typeObject



11
12
13
# File 'lib/cantango/permits/role_group_permit.rb', line 11

def self.type
  :role_group
end

Instance Method Details

#permit?Boolean

In a specific Role based Permit you can use

def permit? user, options = {}
  return if !super(user, :in_group)
  ... permission logic follows

This will call the Permit::Base#permit? instance method (the method below) It will only return true if the user matches the role of the Permit class and the options passed in is set to :in_role

If these confitions are not met, it will return false and thus the outer permit will not run the permission logic to follow

Normally super for #permit? should not be called except for this case, or if subclassing another Permit than Permit::Base

Returns:

  • (Boolean)


45
46
47
# File 'lib/cantango/permits/role_group_permit.rb', line 45

def permit?
  super
end

#permit_nameObject Also known as: role_group



19
20
21
# File 'lib/cantango/permits/role_group_permit.rb', line 19

def permit_name
  self.class.role_group_name self.class
end

#valid_for?(subject) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/cantango/permits/role_group_permit.rb', line 49

def valid_for? subject
  in_role_group? subject
end