Sha256: 4904c71080aa68bb86cc9c7915d67e0237af2085214f68930ba1a1ef0e553119

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require 'rails/generators'
require 'rails/generators/migration'
require 'rails/generators/active_record'

module Cancannible
  module Generators
    class InstallGenerator < Rails::Generators::Base
      include Rails::Generators::Migration

      self.source_paths << File.join(File.dirname(__FILE__), 'templates')

      desc "This generator creates a cancannible initializer file and permissions model migration"

      def create_initializer_file
        template 'cancannible_initializer.rb', 'config/initializers/cancannible.rb'
      end

      def create_permission_migration_file
        migration_template 'migration.rb', 'db/migrate/create_cancannible_permissions.rb'
      end

      def create_permission_model_file
        template 'permission.rb', 'app/models/permission.rb'
      end

      # while methods have moved around this has been the implementation
      # since ActiveRecord 3.0
      def self.next_migration_number(dirname)
        next_migration_number = current_migration_number(dirname) + 1
        if ActiveRecord::Base.timestamped_migrations
          [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
        else
          "%.3d" % next_migration_number
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cancannible-2.1.0 lib/generators/cancannible/install_generator.rb
cancannible-2.0.0 lib/generators/cancannible/install_generator.rb