Sha256: 654f4e43a8bc7d13fb7502ae5e8078020db7ee79b020f37d7a6b20c96b71311f
Contents?: true
Size: 991 Bytes
Versions: 41
Compression:
Stored size: 991 Bytes
Contents
require 'rails/generators' module CmAdmin module Generators class InstallRoleGenerator < Rails::Generators::Base source_root File.expand_path('templates', __dir__) def create_migration generate 'migration', 'CreateCmRole name:string' generate 'migration', 'CreateCmPermission action_name:string action_display_name:string ar_model_name:string scope_name:string cm_role:references' rake 'db:migrate' puts "Created migration" end def create_default_role ::CmRole.create(name: 'Admin') CmAdmin.config.cm_admin_models.each do |model| model.available_actions.each do |action| next if ['custom_action_modal', 'custom_action', 'create', 'update'].include?(action.name) ::CmRole.find_by(name: 'Admin').cm_permissions.where(ar_model_name: model.name, action_name: action.name).first_or_create! end end puts "Created default role" end end end end
Version data entries
41 entries across 41 versions & 1 rubygems