Sha256: d5f202af9d4b16254416b5bce36fa47338eedefb6ce04d37c3d3e9a1f86ad1db

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require "generators/rich"

module Rich
  module Generators

    class AuthlogicUserGenerator < Base

      include Rails::Generators::Migration
      include Rich::Generators::Migration

      desc         "Creates Authlogic model and migration and also registers authenticated model to Rich-CMS."
      argument     :model_name, :type => :string , :default => "user"
      class_option :migrate   , :type => :boolean, :default => false, :aliases => "-m", :desc => "Run 'rake db:migrate' after generating model and migration"

      def register_authentication
        filename = "config/initializers/enrichments.rb"
        line     = "\nRich::Cms::Engine.authenticate(:authlogic, {:class_name => \"#{model_class_name}\", :identifier => :email})"

        return if File.open(filename, "a+").readlines.include? line.strip

        File.open(filename, "a+") do |file|
          file << line
        end
      end

      def generate_model
        template "model.rb", "app/models/#{model_file_name}.rb"
      end

      def generate_session
        template "session.rb", "app/models/#{model_file_name}_session.rb"
      end

      def generate_migration
        migration_template "migration.rb", "db/migrate/create_#{table_name}"
      end

      def migrate
        rake "db:migrate" if options[:migrate]
      end

    protected

      def model_file_name
        model_name.underscore
      end

      def model_class_name
        model_name.classify
      end

      def migration_class_name
        migration_file_name.pluralize.camelize
      end

      def table_name
        model_file_name.underscore.gsub("/", "_").pluralize
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rich_cms-2.1.0 lib/generators/rich/authlogic_user/authlogic_user_generator.rb