Class: Strongmind::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object



52
53
54
55
# File 'lib/generators/strongmind/install_generator.rb', line 52

def self.next_migration_number(path)
  # Add 1 to make sure this happens after the devise migration
  (Time.now.utc.strftime("%Y%m%d%H%M%S").to_i + 1).to_s
end

Instance Method Details

#add_devise_routesObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/strongmind/install_generator.rb', line 35

def add_devise_routes
  devise_route = '
return if defined? Rails::Generators

devise_scope :user do
authenticated do
end
  end
'.dup

  route devise_route
end

#add_dotenv_fileObject



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

def add_dotenv_file
  copy_file "env", ".env"
end

#protect_app_files_and_add_navObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/strongmind/install_generator.rb', line 14

def protect_app_files_and_add_nav
  inject_into_file "app/controllers/application_controller.rb", before: "class ApplicationController < ActionController::Base\n" do
    "require \"strongmind/exceptions\"\n\n"
  end
  inject_into_file "app/controllers/application_controller.rb", after: "class ApplicationController < ActionController::Base\n" do
    "  include StrongMindNav
  before_action :authenticate_user!
  before_action :fetch_common_nav

  # Implement the list of menu items for the application
  # def menu_items
  #   [
  #     { name: 'Home', icon: 'fa-solid fa-house', url: root_path }
  #   ]
  # end

"

  end
end

#run_devise_userObject



8
9
10
11
12
# File 'lib/generators/strongmind/install_generator.rb', line 8

def run_devise_user
  generate "active_record:devise User"
  # overwrite the user model
  copy_file "user.rb", "app/models/user.rb", force: true
end

#uid_migrationObject



48
49
50
# File 'lib/generators/strongmind/install_generator.rb', line 48

def uid_migration
  migration_template "add_uid_and_session_token_to_user.rb", "db/migrate/add_uid_and_session_token_to_user.rb"
end