Class: Rodauth::Rails::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/rodauth/install_generator.rb

Constant Summary collapse

SEQUEL_ADAPTERS =
{
  "postgresql"      => RUBY_ENGINE == "jruby" ? "postgresql" : "postgres",
  "mysql2"          => RUBY_ENGINE == "jruby" ? "mysql" : "mysql2",
  "sqlite3"         => "sqlite",
  "oracle_enhanced" => "oracle",
  "sqlserver"       => RUBY_ENGINE == "jruby" ? "mssql" : "tinytds",
}

Instance Method Summary collapse

Instance Method Details

#add_gemsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/generators/rodauth/install_generator.rb', line 41

def add_gems
  if activerecord? && !sequel?
    gem "sequel-activerecord_connection", "~> 2.0", comment: "Enables Sequel to use Active Record's database connection"
    gem "after_commit_everywhere", "~> 1.1", comment: "Required for Sequel's transaction hooks to work in all cases (on Active Record < 7.2)" if ActiveRecord.version < Gem::Version.new("7.2")
  end
  if argon2?
    gem "argon2", "~> 2.3", comment: "Used by Rodauth for password hashing"
  else
    gem "bcrypt", "~> 3.1", comment: "Used by Rodauth for password hashing"
  end
  if jwt?
    gem "jwt", "~> 2.9", comment: "Used by Rodauth for JWT support"
  end
  gem "tilt", "~> 2.4", comment: "Used by Rodauth for rendering built-in view and email templates"
end

#create_account_modelObject



61
62
63
# File 'lib/generators/rodauth/install_generator.rb', line 61

def 
  template "app/models/account.rb", "app/models/#{table_prefix}.rb"
end

#create_fixturesObject



65
66
67
68
69
70
71
# File 'lib/generators/rodauth/install_generator.rb', line 65

def create_fixtures
  generator_options = ::Rails.configuration.generators.options
  if generator_options[:test_unit][:fixture] && generator_options[:test_unit][:fixture_replacement].nil?
    test_dir = generator_options[:rails][:test_framework] == :rspec ? "spec" : "test"
    template "test/fixtures/accounts.yml", "#{test_dir}/fixtures/#{table_prefix.pluralize}.yml"
  end
end

#create_rodauth_appObject



36
37
38
39
# File 'lib/generators/rodauth/install_generator.rb', line 36

def create_rodauth_app
  template "app/misc/rodauth_app.rb"
  template "app/misc/rodauth_main.rb"
end

#create_rodauth_controllerObject



57
58
59
# File 'lib/generators/rodauth/install_generator.rb', line 57

def create_rodauth_controller
  template "app/controllers/rodauth_controller.rb"
end

#create_rodauth_initializerObject



32
33
34
# File 'lib/generators/rodauth/install_generator.rb', line 32

def create_rodauth_initializer
  template "config/initializers/rodauth.rb"
end

#generate_rodauth_migrationObject



26
27
28
29
30
# File 'lib/generators/rodauth/install_generator.rb', line 26

def generate_rodauth_migration
  invoke "rodauth:migration", migration_features,
    name: "create_rodauth",
    prefix: table_prefix
end

#show_instructionsObject



73
74
75
# File 'lib/generators/rodauth/install_generator.rb', line 73

def show_instructions
  readme "INSTRUCTIONS" if behavior == :invoke && !json? && !jwt?
end