Class: Foobara::Generators::EmptyRubyProjectGenerator::WriteEmptyRubyProjectToDisk
Constant Summary
TruncatedInspect::MAX_LENGTH
Instance Attribute Summary
#paths_to_source_code
#is_subcommand
#exception, #outcome
#error_collection
#inputs, #raw_inputs
Class Method Summary
collapse
Instance Method Summary
collapse
#delete_old_files_if_needed, #generate_generated_files_json, #generated_files_json_filename, #run_cmd_and_return_output, #run_cmd_and_write_output, #stats, #write_all_files_to_disk, #write_file_to_disk
Methods inherited from Command
install!, reset_all
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
#initialize
#domain_map, #domain_map!, #run_mapped_subcommand!
#run_subcommand!, #subcommand?
#load_entities, #load_records
#auto_detect_current_transactions, #commit_transaction, #open_transaction, #opened_transactions, #relevant_entity_classes, #rollback_transaction, #transactions
#state_machine
#halt!, #run, #run!, #run_execute, #succeed, #success?, #validate, #validate_records
#initialize
#cast_and_validate_inputs, #initialize, #method_missing, #respond_to_missing?, #respond_to_missing_for_inputs?
#inspect, truncating
Class Method Details
.generator_key ⇒ Object
10
11
12
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 10
def generator_key
"ruby-project"
end
|
Instance Method Details
#bundle_install ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 86
def bundle_install
puts "bundling..."
do_it = proc do
Open3.popen3("bundle install") do |_stdin, _stdout, stderr, wait_thr|
exit_status = wait_thr.value
unless exit_status.success?
raise "could not bundle install. #{stderr.read}"
end
end
end
if Bundler.respond_to?(:with_unbundled_env)
Bundler.with_unbundled_env(&do_it)
else
do_it.call
end
end
|
#create_output_directory_if_needed ⇒ Object
38
39
40
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 38
def create_output_directory_if_needed
FileUtils.mkdir_p output_directory
end
|
#default_output_directory ⇒ Object
60
61
62
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 60
def default_output_directory
project_config.org_slash_project_kebab
end
|
#execute ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 26
def execute
create_output_directory_if_needed
if
end
generate_file_contents
write_all_files_to_disk
run_post_generation_tasks
output
end
|
46
47
48
49
50
51
52
53
54
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 46
def
run_subcommand!(
ExtractRepo,
repo_url_or_path: ,
paths: ,
delete_extracted:,
output_path: output_directory
)
end
|
42
43
44
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 42
def
!!
end
|
#generate_file_contents ⇒ Object
64
65
66
67
68
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 64
def generate_file_contents
puts "generating..."
self.paths_to_source_code = run_subcommand!(GenerateEmptyRubyProject, project_config.attributes)
end
|
#git_add_all ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 145
def git_add_all
cmd = "git add ."
Open3.popen3(cmd) do |_stdin, _stdout, stderr, wait_thr|
exit_status = wait_thr.value
unless exit_status.success?
raise "could not #{cmd}\n#{stderr.read}"
end
end
end
|
#git_add_remote_origin ⇒ Object
183
184
185
186
187
188
189
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 183
def git_add_remote_origin
unless system("git remote add origin git@github.com:#{project_config.org_slash_project_kebab}.git")
raise "could not git remote add origin git@github.com:#{project_config.org_slash_project_kebab}.git"
end
end
|
#git_branch_main ⇒ Object
191
192
193
194
195
196
197
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 191
def git_branch_main
unless system("git branch -M main")
raise "could not git branch -M main"
end
end
|
#git_commit ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 158
def git_commit
Open3.popen3("git commit -m 'Create ruby project files'") do |_stdin, stdout, stderr, wait_thr|
exit_status = wait_thr.value
unless exit_status.success?
raise "could not git commit -m 'Initial commit'. OUTPUT\n#{stdout.read}\nERROR:#{stderr.read}"
end
end
end
|
#git_init ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 132
def git_init
cmd = "git init"
Open3.popen3(cmd) do |_stdin, _stdout, stderr, wait_thr|
exit_status = wait_thr.value
unless exit_status.success?
raise "could not #{cmd}\n#{stderr.read}"
end
end
end
|
#github_create_repo ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 170
def github_create_repo
puts "pushing to github..."
cmd = "gh repo create --private #{project_config.org_slash_project_kebab}"
Open3.popen3(cmd) do |_stdin, _stdout, _stderr, wait_thr|
exit_status = wait_thr.value
unless exit_status.success?
warn "WARNING: could not #{cmd}"
end
end
end
|
#make_bin_files_executable ⇒ Object
124
125
126
127
128
129
130
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 124
def make_bin_files_executable
Dir["bin/*"].each do |file|
if File.file?(file)
system("chmod u+x #{file}")
end
end
end
|
#output ⇒ Object
219
220
221
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 219
def output
"\nDone. #{stats}"
end
|
#output_directory ⇒ Object
56
57
58
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 56
def output_directory
inputs[:output_directory] || default_output_directory
end
|
#push_to_github ⇒ Object
199
200
201
202
203
204
205
206
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 199
def push_to_github
Open3.popen3("git push -u origin main") do |_stdin, _stdout, stderr, wait_thr|
exit_status = wait_thr.value
unless exit_status.success?
warn "WARNING: could not git push -u origin main \n #{stderr.read}"
end
end
end
|
#rbenv_bundler_on ⇒ Object
208
209
210
211
212
213
214
215
216
217
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 208
def rbenv_bundler_on
Open3.popen3("rbenv bundler on") do |_stdin, _stdout, stderr, wait_thr|
exit_status = wait_thr.value
unless exit_status.success?
warn "WARNING: could not rbenv bundler on \n #{stderr.read}"
end
end
end
|
#rubocop_autocorrect ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 108
def rubocop_autocorrect
puts "linting..."
do_it = -> { run_cmd_and_return_output("bundle exec rubocop --no-server -A") }
if Bundler.respond_to?(:with_unbundled_env)
Bundler.with_unbundled_env do
do_it.call
end
else
do_it.call
end
end
|
#run_post_generation_tasks ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'foobara-empty-ruby-project-generator-0.0.18/src/write_empty_ruby_project_to_disk.rb', line 70
def run_post_generation_tasks
Dir.chdir output_directory do
bundle_install
make_bin_files_executable
rubocop_autocorrect
git_init unless
git_add_all
git_commit
github_create_repo
git_add_remote_origin
git_branch_main
push_to_github
rbenv_bundler_on
end
end
|