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

Version Path
cm-admin-3.0.14 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.13 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.12 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.11 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.10 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.9 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.8 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.7 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.6 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.5 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.4 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.3 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.2 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.1 lib/generators/cm_admin/install_role_generator.rb
cm-admin-3.0.0 lib/generators/cm_admin/install_role_generator.rb
cm-admin-2.4.6 lib/generators/cm_admin/install_role_generator.rb
cm-admin-2.4.5 lib/generators/cm_admin/install_role_generator.rb
cm-admin-2.4.4 lib/generators/cm_admin/install_role_generator.rb
cm-admin-2.4.3 lib/generators/cm_admin/install_role_generator.rb
cm-admin-2.4.2 lib/generators/cm_admin/install_role_generator.rb