Class: ActiveAdmin::Generators::DeviseGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/active_admin/devise/devise_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_default_user_to_migrationObject



37
38
39
40
41
42
43
44
45
# File 'lib/generators/active_admin/devise/devise_generator.rb', line 37

def add_default_user_to_migration
  # Don't assume that we have a migration!
  devise_migrations = Dir["db/migrate/*_devise_create_#{table_name}.rb"]
  if devise_migrations.size > 0
    inject_into_file  Dir["db/migrate/*_devise_create_#{table_name}.rb"].first, 
                      "# Create a default user\n    #{class_name}.create!(:email => '[email protected]', :password => 'password', :password_confirmation => 'password')\n\n    ",
                      :before => "add_index :#{table_name}, :email"
  end
end

#create_admin_userObject



21
22
23
# File 'lib/generators/active_admin/devise/devise_generator.rb', line 21

def create_admin_user
  invoke "devise", [name]
end

#install_deviseObject



11
12
13
14
15
16
17
18
19
# File 'lib/generators/active_admin/devise/devise_generator.rb', line 11

def install_devise
  require 'devise'
  if File.exists?(File.join(destination_root, "config", "initializers", "devise.rb"))
    log :generate, "No need to install devise, already done."
  else
    log :generate, "devise:install"
    invoke "devise:install"
  end
end

#remove_registerable_from_modelObject



25
26
27
28
29
30
# File 'lib/generators/active_admin/devise/devise_generator.rb', line 25

def remove_registerable_from_model
  unless options[:registerable]
    model_file = File.join(destination_root, "app", "models", "#{file_path}.rb")
    gsub_file model_file, /\:registerable([.]*,)?/, ""
  end
end

#set_namespace_for_pathObject



32
33
34
35
# File 'lib/generators/active_admin/devise/devise_generator.rb', line 32

def set_namespace_for_path
  routes_file = File.join(destination_root, "config", "routes.rb")
  gsub_file routes_file, /devise_for :#{table_name}/, "devise_for :#{table_name}, ActiveAdmin::Devise.config"
end