Class: ExceptionHunter::CreateUsersGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/exception_hunter/create_users/create_users_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_admin_userObject



24
25
26
# File 'lib/generators/exception_hunter/create_users/create_users_generator.rb', line 24

def create_admin_user
  invoke 'devise', [name], routes: false
end

#install_deviseObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/exception_hunter/create_users/create_users_generator.rb', line 5

def install_devise
  begin
    require 'devise'
  rescue LoadError
    log :error, 'Please install devise and require add it to your gemfile or run with --skip-users'
    exit(false)
  end

  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_modelObject



28
29
30
31
32
33
# File 'lib/generators/exception_hunter/create_users/create_users_generator.rb', line 28

def remove_registerable_from_model
  return if options[:registerable]

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