Sha256: 0cc1c47e3699763c8d259fcf2bfbd512e21cc6b9e8a947ddadbba1a67c1dacca

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

require 'rails/generators/migration'

module Rolify
  module Generators
    class RoleGenerator < Rails::Generators::Base
      include Rails::Generators::Migration

      source_root File.expand_path('../templates', __FILE__)
      argument :role_cname, :type => :string, :default => "Role"
      argument :user_cname, :type => :string, :default => "User"

      desc "Generates a model with the given NAME and a migration file."

      def generate_role
        template "role.rb", "app/models/role.rb"
        inject_into_class(model_path, user_cname.camelize) do
          "  include Rolify\n" + "  has_and_belongs_to_many :#{role_cname.tableize}\n"
        end
      end

      def copy_role_file
        migration_template "migration.rb", "db/migrate/rolify_create_#{role_cname.tableize}"
      end

      def model_path
        File.join("app", "models", "#{user_cname.underscore}.rb")
      end
      
      def self.next_migration_number(path)
        Time.now.utc.strftime("%Y%m%d%H%M%S")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rolify-0.4.0 lib/generators/rolify/role/role_generator.rb
rolify-0.3.0 lib/generators/rolify/role/role_generator.rb
rolify-0.2.1 lib/generators/rolify/role/role_generator.rb
rolify-0.2.0 lib/generators/rolify/role/role_generator.rb