Class: DeviseTokenAuth::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
InstallGeneratorHelpers, Rails::Generators::Migration
Defined in:
lib/generators/devise_token_auth/install_generator.rb

Instance Method Summary collapse

Methods included from InstallGeneratorHelpers

included

Instance Method Details

#copy_migrationsObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/generators/devise_token_auth/install_generator.rb', line 12

def copy_migrations
  if self.class.migration_exists?('db/migrate', "devise_token_auth_create_#{user_class.pluralize.gsub('::','').underscore}")
    say_status('skipped', "Migration 'devise_token_auth_create_#{user_class.pluralize.gsub('::','').underscore}' already exists")
  else
    migration_template(
      'devise_token_auth_create_users.rb.erb',
      "db/migrate/devise_token_auth_create_#{user_class.pluralize.gsub('::','').underscore}.rb"
    )
  end
end

#create_user_modelObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/generators/devise_token_auth/install_generator.rb', line 23

def create_user_model
  fname = "app/models/#{user_class.underscore}.rb"
  if File.exist?(File.join(destination_root, fname))
    inclusion = 'include DeviseTokenAuth::Concerns::User'
    unless parse_file_for_line(fname, inclusion)

      active_record_needle = (Rails::VERSION::MAJOR == 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
      inject_into_file fname, after: "class #{user_class} < #{active_record_needle}\n" do <<-'RUBY'
        # Include default devise modules.
        devise :database_authenticatable, :registerable,
                :recoverable, :rememberable, :trackable, :validatable,
                :confirmable, :omniauthable
        include DeviseTokenAuth::Concerns::User
        RUBY
      end
    end
  else
    template('user.rb.erb', fname)
  end
end