# File lib/generators/devise_token_auth/install_generator.rb, line 86 def primary_key_string key_string = options[:primary_key_type] ", id: :#{key_string}" if key_string end
class DeviseTokenAuth::InstallGenerator
Public Class Methods
next_migration_number(path)
click to toggle source
# File lib/generators/devise_token_auth/install_generator.rb, line 46 def self.next_migration_number(path) Time.zone.now.utc.strftime('%Y%m%d%H%M%S') end
Public Instance Methods
copy_migrations()
click to toggle source
# 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_model()
click to toggle source
# 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
Private Instance Methods
database_name()
click to toggle source
# File lib/generators/devise_token_auth/install_generator.rb, line 70 def database_name ActiveRecord::Base.connection.class.name end
database_version()
click to toggle source
# File lib/generators/devise_token_auth/install_generator.rb, line 74 def database_version ActiveRecord::Base.connection.select_value('SELECT VERSION()') end
json_supported_database?()
click to toggle source
# File lib/generators/devise_token_auth/install_generator.rb, line 50 def json_supported_database? (postgres? && postgres_correct_version?) || (mysql? && mysql_correct_version?) end
mysql?()
click to toggle source
# File lib/generators/devise_token_auth/install_generator.rb, line 62 def mysql? database_name == 'ActiveRecord::ConnectionAdapters::MysqlAdapter' end
mysql_correct_version?()
click to toggle source
# File lib/generators/devise_token_auth/install_generator.rb, line 66 def mysql_correct_version? database_version > '5.7.7' end
postgres?()
click to toggle source
# File lib/generators/devise_token_auth/install_generator.rb, line 54 def postgres? database_name == 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter' end
postgres_correct_version?()
click to toggle source
# File lib/generators/devise_token_auth/install_generator.rb, line 58 def postgres_correct_version? database_version > '9.3' end
primary_key_string()
click to toggle source
primary_key_type()
click to toggle source
# File lib/generators/devise_token_auth/install_generator.rb, line 82 def primary_key_type primary_key_string if rails_5_or_newer? end
rails_5_or_newer?()
click to toggle source
# File lib/generators/devise_token_auth/install_generator.rb, line 78 def rails_5_or_newer? Rails::VERSION::MAJOR >= 5 end