Sha256: 7520fc98570c6edd3014a584c5d2193927ffe9af41918cb5a02031935876f9be

Contents?: true

Size: 1006 Bytes

Versions: 2

Compression:

Stored size: 1006 Bytes

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  
          "  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

2 entries across 2 versions & 1 rubygems

Version Path
rolify-0.1.0 lib/generators/rolify/role/role_generator.rb
rolify-0.0.1 lib/generators/rolify/role/role_generator.rb