Class: Role

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
Permissify::ModelClass, SystemFixtures::Roles
Includes:
Permissify::Model
Defined in:
lib/generators/permissify/role/template/role.rb

Constant Summary collapse

DOMAIN_TYPES =
%w(Admin Dealer Corporation Brand Merchant)
PERMISSIFIED_ABILITY_APPLICABILITY =
'Role'

Instance Attribute Summary

Attributes included from Permissify::Model

#from, #from_permissions_model

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Permissify::ModelClass

create_seeds, create_with_id, force_seed_id, locate, underscored_name_symbol

Methods included from Permissify::Model

#allows?, #establish_from_permissions_model, #initialize_permissions, #remove_permissions, #underscored_name_symbol, #update_permissions

Class Method Details

.force_seed_id(table, permissions_model, id) ⇒ Object



21
22
23
24
# File 'lib/generators/permissify/role/template/role.rb', line 21

def force_seed_id(table, permissions_model, id)
  # TODO : account for different db adapters? written against mysql.
  ActiveRecord::Base.connection.execute "UPDATE #{table}s SET id=#{id} WHERE id=#{permissions_model.id};"
end

Instance Method Details

#copy_non_permissions_valuesObject



36
37
38
39
40
# File 'lib/generators/permissify/role/template/role.rb', line 36

def copy_non_permissions_values
  self.domain_type = self.from_permissions_model.domain_type
  self.managers = self.from_permissions_model.managers
  self.manages = self.from_permissions_model.manages
end

#default_non_permissions_valuesObject



31
32
33
34
# File 'lib/generators/permissify/role/template/role.rb', line 31

def default_non_permissions_values
  self.domain_type = DOMAIN_TYPES.last if self.domain_type.blank?
  self.name = self.name.gsub("'","")
end

#initialize_non_permission_valuesObject



27
28
29
# File 'lib/generators/permissify/role/template/role.rb', line 27

def initialize_non_permission_values
  establish_from_permissions_model.nil? ? default_non_permissions_values : copy_non_permissions_values
end

#remove(permissions_list) ⇒ Object



42
# File 'lib/generators/permissify/role/template/role.rb', line 42

def remove(permissions_list); permissions_list.each{|permission| self.permissions.delete(permission)}; save; end