12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/cli/commands/new_app/files/app.rb', line 12
def self.content(app_name)
snake_case_app_name = app_name.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
<<~RUBY
# typed: true
# frozen_string_literal: true
# First: check if all gems are installed correctly
require "bundler/setup"
# Second: load all gems
# we have runtime/production ("default") and development gems ("development")
Bundler.require(:default)
Bundler.require(:development) if ENV["RACK_ENV"] == "development"
Bundler.require(:test) if ENV["RACK_ENV"] == "test"
# Third: load all initializers
Dir[File.join(__dir__, "config/initializers", "*.rb")].each { require(_1) }
# Fourth: load all application code
loader = Zeitwerk::Loader.new
loader.tag = File.basename(__FILE__, ".rb")
[
"/app",
"/app/models",
"/app/services",
].each do |root_namespace|
# a root namespace skips the auto-infered module for this folder
# so we don't have to write e.g. `Models::` or `Services::`
loader.push_dir("\#{File.dirname(__FILE__)}\#{root_namespace}")
end
loader.setup
# Fifth: load configs
Dir[File.join(__dir__, "config", "*.rb")].each { require(_1) }
class #{app_name} < Kirei::App
# Kirei configuration
config.app_name = "#{snake_case_app_name}"
end
loader.eager_load
RUBY
end
|