Class: Shakha::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/generators/shakha/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_initializerObject



17
18
19
# File 'lib/generators/shakha/install/install_generator.rb', line 17

def copy_initializer
  template "shakha.rb.erb", "config/initializers/shakha.rb"
end

#copy_migrationObject



13
14
15
# File 'lib/generators/shakha/install/install_generator.rb', line 13

def copy_migration
  migration_template "create_shakha_tables.rb.erb", "db/migrate/create_shakha_tables.rb"
end

#enable_cookies_for_api_modeObject



31
32
33
34
35
36
# File 'lib/generators/shakha/install/install_generator.rb', line 31

def enable_cookies_for_api_mode
  return unless api_only_app?

  application "config.middleware.use ActionDispatch::Cookies"
  say_status :insert, "config/application.rb -> ActionDispatch::Cookies (API mode)", :green
end

#inject_application_controllerObject



21
22
23
24
25
26
27
28
29
# File 'lib/generators/shakha/install/install_generator.rb', line 21

def inject_application_controller
  path = "app/controllers/application_controller.rb"
  full_path = File.join(destination_root, path)
  return unless File.exist?(full_path)
  return if File.read(full_path).include?("Shakha::ControllerHelpers")

  inject_into_class path, "ApplicationController", "  include Shakha::ControllerHelpers\n"
  say_status :insert, "ApplicationController -> include Shakha::ControllerHelpers", :green
end

#print_post_installObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/generators/shakha/install/install_generator.rb', line 38

def print_post_install
  origin = Shakha.config.app_origin || "http://localhost:3000"

  say ""
  say "  Shakha installed!", :green
  say "  #{'' * 50}", :green
  say ""
  say "  1. Set environment variables:", :yellow
  say "     GOOGLE_CLIENT_ID", :cyan
  say "     GOOGLE_CLIENT_SECRET", :cyan
  say ""
  say "  2. (Optional) GitHub:", :yellow
  say "     GITHUB_CLIENT_ID / GITHUB_CLIENT_SECRET", :cyan
  say ""
  say "  3. For SPA: set ALLOWED_REDIRECT_ORIGINS", :yellow
  say ""
  say "  4. Run migrations:", :yellow
  say "     bin/rails db:migrate", :cyan
  say ""
  say "  5. Google Cloud Console redirect URI:", :yellow
  say "     #{origin}/auth/shakha/google/callback", :cyan
  say ""
  say "  6. GitHub OAuth App callback URL:", :yellow
  say "     #{origin}/auth/shakha/github/callback", :cyan
  say "  #{'' * 50}", :green
  say ""
  say "  Tell your frontend dev:", :cyan
  say "    Sign in:  #{origin}/auth/shakha/google"
  say "    Session:  GET #{origin}/auth/shakha/session"
  say "    Auth:     Authorization: Bearer <token>"
  say "    Sign out: DELETE #{origin}/auth/shakha/sign_out"
  say ""
end