Sha256: bd5d3ee73ebab9a1199e25535a555fc4d1feafdf1b2d2699d91c3880af108514

Contents?: true

Size: 1.96 KB

Versions: 4

Compression:

Stored size: 1.96 KB

Contents

require 'rails/generators/active_record'
require 'generators/devise/orm_helpers'

module GoogleAuthentication
  module Generators # :nodoc:
    class GoogleAuthenticationGenerator < ActiveRecord::Generators::Base # :nodoc:
      namespace "google_authentication"
      source_root File.expand_path("../../templates", __FILE__)

      # include some helpers from devise
      include Devise::Generators::OrmHelpers

      # accept same arguments as devise generator with google tuned defaults
      argument :attributes, :type => :array, :default => ['first_name:string', 'last_name:string'], :banner => "field:type field:type"

      desc "Generates a model with the given NAME with google_authentication " <<
           "configuration plus a migration file which create it."

      # Generate the model without a migration file using the active_record generator
      def generate_model
        invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
      end

      # Build the migration files for the given model
      def copy_devise_migration
        migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
      end

      # Insert gem activation code into the selected class
      def inject_google_authentication_content
        inject_into_class(model_path, class_name) do
          return nil unless model_exists?
          "  # You can add other devise modules here as arguments, as in devise calls. :omniauthable module is always added\n" <<
          "  # and forbidden devise modules are automatically removed (see GoogleAuthentication::ActsAsGoogleUser::FORBIDDEN_MODULES)\n" <<
          "  # if you change this line, remember to edit the generated migration\n" <<
          "  acts_as_google_user\n"
        end
      end

      # Show a readme file with further instructions after installation
      def show_readme
        readme "MODEL.warning" if behavior == :invoke && class_name != 'User'
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
google_authentication-0.2.0 lib/generators/google_authentication/google_authentication_generator.rb
google_authentication-0.1.2 lib/generators/google_authentication/google_authentication_generator.rb
google_authentication-0.1.1 lib/generators/google_authentication/google_authentication_generator.rb
google_authentication-0.1.0 lib/generators/google_authentication/google_authentication_generator.rb