Sha256: 1503a0feebf30d937e1780652e9c0a10fd110a070c1ba4f4648b4b649626d54f

Contents?: true

Size: 1.82 KB

Versions: 15

Compression:

Stored size: 1.82 KB

Contents

require 'securerandom'

module Petergate
  module Generators
    class InstallGenerator < Rails::Generators::Base
      include Rails::Generators::Migration
      source_root File.expand_path("../templates", __FILE__)
      class_option :orm

      desc "Sets up rails project for Petergate Authorizations"
      def self.next_migration_number(path)
        sleep 1
        Time.now.utc.strftime("%Y%m%d%H%M%S")
      end

      def insert_into_user_model
        inject_into_file "app/models/user.rb", after: /^class\sUser < ActiveRecord::Base|^class User < ApplicationRecord/ do
          <<-'RUBY'

  ############################################################################################
  ## PeterGate Roles                                                                        ##
  ## The :user role is added by default and shouldn't be included in this list.             ##
  ## The :root_admin can access any page regardless of access settings. Use with caution!   ##
  ## The multiple option can be set to true if you need users to have multiple roles.       ##
  petergate(roles: [:admin, :editor], multiple: false)                                      ##
  ############################################################################################ 
 
          RUBY
        end
      end

  #     def insert_into_application_controller
  #       inject_into_file "app/controllers/application_controller.rb", after: /^class\sApplicationController\s<\sActionController::Base/ do
  #         <<-'RUBY'

  # access(all: [:index, :show])
 
  #         RUBY
  #       end
  #     end

      def create_migrations
        Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath|
          name = File.basename(filepath)
          migration_template "migrations/#{name}", "db/migrate/#{name}"
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
petergate-3.0.0 lib/generators/petergate/install_generator.rb
petergate-2.0.1 lib/generators/petergate/install_generator.rb
petergate-1.9.1 lib/generators/petergate/install_generator.rb
petergate-1.8.1 lib/generators/petergate/install_generator.rb
petergate-1.8.0 lib/generators/petergate/install_generator.rb
petergate-1.7.5 lib/generators/petergate/install_generator.rb
petergate-1.7.3 lib/generators/petergate/install_generator.rb
petergate-1.7.1 lib/generators/petergate/install_generator.rb
petergate-1.7.0 lib/generators/petergate/install_generator.rb
petergate-1.6.9 lib/generators/petergate/install_generator.rb
petergate-1.6.8 lib/generators/petergate/install_generator.rb
petergate-1.6.7 lib/generators/petergate/install_generator.rb
petergate-1.6.6 lib/generators/petergate/install_generator.rb
petergate-1.6.5 lib/generators/petergate/install_generator.rb
petergate-1.6.4 lib/generators/petergate/install_generator.rb