Class: ActiveAdmin::Generators::DeviseGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- ActiveAdmin::Generators::DeviseGenerator
- Defined in:
- lib/generators/active_admin/devise/devise_generator.rb
Constant Summary collapse
- RESERVED_NAMES =
[:active_admin_user]
Instance Method Summary collapse
- #add_default_user_to_seed ⇒ Object
- #create_admin_user ⇒ Object
- #install_devise ⇒ Object
- #remove_registerable_from_model ⇒ Object
- #set_namespace_for_path ⇒ Object
Instance Method Details
#add_default_user_to_seed ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/generators/active_admin/devise/devise_generator.rb', line 58 def add_default_user_to_seed seeds_paths = Rails.application.paths["db/seeds.rb"] seeds_file = seeds_paths.existent.first return if seeds_file.nil? || ![:default_user] create_user_code = "#{class_name}.create!(email: '[email protected]', password: 'password', password_confirmation: 'password') if Rails.env.development?" append_to_file seeds_file, create_user_code end |
#create_admin_user ⇒ Object
39 40 41 42 43 44 |
# File 'lib/generators/active_admin/devise/devise_generator.rb', line 39 def create_admin_user if RESERVED_NAMES.include?(name.underscore) raise ActiveAdmin::GeneratorError, "The name #{name} is reserved by Active Admin" end invoke "devise", [name] end |
#install_devise ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/generators/active_admin/devise/devise_generator.rb', line 19 def install_devise begin Dependency.devise! Dependency::Requirements::DEVISE rescue DependencyError => e raise ActiveAdmin::GeneratorError, "#{e.} If you don't want to use devise, run the generator with --skip-users." end require "devise" initializer_file = File.join(destination_root, "config", "initializers", "devise.rb") if File.exist?(initializer_file) log :generate, "No need to install devise, already done." else log :generate, "devise:install" invoke "devise:install" end end |
#remove_registerable_from_model ⇒ Object
46 47 48 49 50 51 |
# File 'lib/generators/active_admin/devise/devise_generator.rb', line 46 def remove_registerable_from_model unless [:registerable] model_file = File.join(destination_root, "app", "models", "#{file_path}.rb") gsub_file model_file, /\:registerable([.]*,)?/, "" end end |
#set_namespace_for_path ⇒ Object
53 54 55 56 |
# File 'lib/generators/active_admin/devise/devise_generator.rb', line 53 def set_namespace_for_path routes_file = File.join(destination_root, "config", "routes.rb") gsub_file routes_file, /devise_for :#{plural_table_name}$/, "devise_for :#{plural_table_name}, ActiveAdmin::Devise.config" end |