Sha256: c4797337541b8e0037a26d487351aa318b9cfbba0e95a1e550593063d4bb157a

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

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

module Chive
  module Generators
    class DeviseGenerator < Rails::Generators::Base
      include ActiveRecord::Generators::Migration

      desc <<-DESC
Install Devise with Chive defaults.
      DESC

      class_option :user, type: :string, default: 'User', desc: 'The user model'

      def manifest
        Rails::Generators.invoke 'devise:install', [], behavior: behavior
        # @todo The User model should be configurable
        Rails::Generators.invoke 'devise', [options[:user]], behavior: behavior
        # @todo Adding a name may or may not be necessary
        migration_template 'add_name_to_devise.rb.tt', "db/migrate/add_name_to_#{options[:user].downcase.pluralize}.rb", {
          migration_file_name: "add_name_to_#{options[:user].downcase.pluralize}"
        }
      end

      private

      def source_paths
        @source_paths ||= [File.join(Chive::Engine.root, 'templates')]
      end

      def user
        options[:user].camelize.singularize
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
chive-0.2.3 lib/generators/chive/devise_generator.rb
chive-0.2.2 lib/generators/chive/devise_generator.rb
chive-0.2.1 lib/generators/chive/devise_generator.rb
chive-0.2.0 lib/generators/chive/devise_generator.rb
chive-0.1.1 lib/generators/chive/devise_generator.rb
chive-0.1.0 lib/generators/chive/devise_generator.rb