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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/inline_forms_installer/creator.rb', line 26
def create(app_name)
def self.skiprvm
options[:skiprvm]
end
def self.runtest
options[:runtest]
end
def self.install_example?
options[:example]
end
def self.database
@database ||= options[:database]
return @database if DATABASE_OPTIONS.include?(@database)
say "No Database specified please choose one database #{DATABASE_OPTIONS.join(' | ')}", :red
while !DATABASE_OPTIONS.include?(@database)
@database = ask "Database: "
return @database if DATABASE_OPTIONS.include?(@database)
end
end
def self.using_sqlite?
database == "sqlite"
end
def self.email
options[:email]
end
def self.password
options[:password]
end
if install_example? && !using_sqlite?
say "--example can only be used with an sqlite development database", :red
exit 1
end
inline_forms_version = InlineFormsInstaller.inline_forms_version
say "Creating #{app_name} with inline_forms v#{inline_forms_version} and development database #{database}...", :green
regex = /\A[0-9a-zA-Z][0-9a-zA-Z_-]+[0-9a-zA-Z]\Z/
if !regex.match(app_name)
say "Error: APP must match #{regex.source}", :red
exit 1
end
if File.exist?(app_name)
say "Error: APP exists", :red
exit 1
end
target_ruby = InlineFormsInstaller::TARGET_RUBY_VERSION
require "rvm"
if RVM.current && !options[:skiprvm]
say "Installing inline_forms with RVM", :green
else
say "Installing inline_forms without RVM", :green
end
say "Installing with #{options[:database]}", :green
options.each do |k, v|
ENV[k] = v.to_s
end
ENV["using_sqlite"] = using_sqlite?.to_s
ENV["database"] = database
ENV["install_example"] = install_example?.to_s
ENV["ruby_version"] = target_ruby
ENV["inline_forms_rvm_gemset"] = app_name if RVM.current && !options[:skiprvm]
ENV["inline_forms_version"] = inline_forms_version
ENV["inline_forms_installer_version"] = InlineFormsInstaller::VERSION
ENV["INLINE_FORMS_INSTALLER_ROOT"] = InlineFormsInstaller.gem_root
ENV["INLINE_FORMS_ROOT"] = InlineFormsInstaller.inline_forms_gem_root
app_template_file = File.join(__dir__, "app_template.rb")
require "rubygems"
compatible_rails =
begin
Gem::Specification
.find_all_by_name("rails")
.map(&:version)
.select { |v| v >= Gem::Version.new("7.2") && v < Gem::Version.new("7.3") }
.max
rescue StandardError
nil
end
rails_invocation = compatible_rails ? "rails _#{compatible_rails}_" : "rails"
say "Generating app with: #{rails_invocation} new ...", :green
unless run("#{rails_invocation} new #{app_name} -m #{app_template_file} --skip-bundle --skip-bootsnap --javascript=importmap")
say "Rails could not create the app '#{app_name}', maybe because it is a reserved word...", :red
exit 1
end
end
|