Class: Bulldozer::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Bulldozer::AppBuilder
show all
- Extended by:
- Forwardable
- Includes:
- Actions
- Defined in:
- lib/bulldozer/app_builder.rb
Instance Method Summary
collapse
Methods included from Actions
#action_mailer_asset_host, #action_mailer_host, #configure_environment, #expand_json, #replace_in_file
Instance Method Details
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/bulldozer/app_builder.rb', line 181
def configure_action_mailer
action_mailer_host "development", %{"localhost:3000"}
action_mailer_asset_host "development", %{"http://localhost:3000"}
action_mailer_host "test", %{"www.example.com"}
action_mailer_asset_host "test", %{"http://www.example.com"}
action_mailer_host "production", %{ENV.fetch("APPLICATION_HOST")}
action_mailer_asset_host(
"production",
%{ENV.fetch("ASSET_HOST", ENV.fetch("APPLICATION_HOST"))},
)
end
|
172
173
174
|
# File 'lib/bulldozer/app_builder.rb', line 172
def configure_action_mailer_in_specs
copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb'
end
|
224
225
226
227
228
229
230
231
232
233
234
|
# File 'lib/bulldozer/app_builder.rb', line 224
def configure_automatic_deployment
deploy_command = " deployment:\n staging:\n branch: master\n commands:\n - bin/deploy staging\n YML\n\n append_file \"circle.yml\", deploy_command\nend\n".strip_heredoc
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/bulldozer/app_builder.rb', line 82
def configure_generators
config = "\nconfig.generators do |generate|\n generate.helper false\n generate.javascripts false\n generate.request_specs false\n generate.routing_specs false\n generate.stylesheets false\n generate.test_framework :rspec\n generate.view_specs false\nend\n\n RUBY\n\n inject_into_class 'config/application.rb', 'Application', config\nend\n"
|
167
168
169
170
|
# File 'lib/bulldozer/app_builder.rb', line 167
def configure_i18n_for_missing_translations
raise_on_missing_translations_in("development")
raise_on_missing_translations_in("test")
end
|
100
101
102
|
# File 'lib/bulldozer/app_builder.rb', line 100
def configure_local_mail
copy_file "email.rb", "config/initializers/email.rb"
end
|
69
70
71
72
73
74
75
|
# File 'lib/bulldozer/app_builder.rb', line 69
def configure_quiet_assets
config = "config.assets.quiet = true\n RUBY\n\n inject_into_class \"config/application.rb\", \"Application\", config\nend\n"
|
176
177
178
179
|
# File 'lib/bulldozer/app_builder.rb', line 176
def configure_time_formats
remove_file "config/locales/en.yml"
template "config_locales_en.yml.erb", "config/locales/en.yml"
end
|
#copy_dockerfiles ⇒ Object
32
33
34
35
|
# File 'lib/bulldozer/app_builder.rb', line 32
def copy_dockerfiles
template "dockerfile.erb", "dockerfile"
copy_file "docker-compose.yml", "docker-compose.yml"
end
|
#copy_dotfiles ⇒ Object
215
216
217
|
# File 'lib/bulldozer/app_builder.rb', line 215
def copy_dotfiles
directory("dotfiles", ".")
end
|
#copy_miscellaneous_files ⇒ Object
249
250
251
252
253
|
# File 'lib/bulldozer/app_builder.rb', line 249
def copy_miscellaneous_files
copy_file "browserslist", "browserslist"
copy_file "errors.rb", "config/initializers/errors.rb"
copy_file "json_encoding.rb", "config/initializers/json_encoding.rb"
end
|
#create_database ⇒ Object
149
150
151
|
# File 'lib/bulldozer/app_builder.rb', line 149
def create_database
bundle_command "exec rails db:create db:migrate"
end
|
#create_github_repo(repo_name) ⇒ Object
236
237
238
|
# File 'lib/bulldozer/app_builder.rb', line 236
def create_github_repo(repo_name)
run "hub create #{repo_name}"
end
|
#create_heroku_apps(flags) ⇒ Object
219
220
221
222
|
# File 'lib/bulldozer/app_builder.rb', line 219
def create_heroku_apps(flags)
create_staging_heroku_app(flags)
create_production_heroku_app(flags)
end
|
#customize_error_pages ⇒ Object
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
# File 'lib/bulldozer/app_builder.rb', line 255
def customize_error_pages
meta_tags =" <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"initial-scale=1\" />\n EOS\n\n %w(500 404 422).each do |page|\n path = \"public/\#{page}.html\"\n if File.exist?(path)\n inject_into_file path, meta_tags, after: \"<head>\\n\"\n replace_in_file path, /<!--.+-->\\n/, ''\n end\n end\nend\n"
|
#disallow_wrapping_parameters ⇒ Object
140
141
142
|
# File 'lib/bulldozer/app_builder.rb', line 140
def disallow_wrapping_parameters
remove_file "config/initializers/wrap_parameters.rb"
end
|
#enable_rack_canonical_host ⇒ Object
104
105
106
107
108
109
110
|
# File 'lib/bulldozer/app_builder.rb', line 104
def enable_rack_canonical_host
config = " config.middleware.use Rack::CanonicalHost, ENV.fetch(\"APPLICATION_HOST\")\n RUBY\n\n configure_environment \"production\", config\nend\n"
|
#enable_rack_deflater ⇒ Object
112
113
114
|
# File 'lib/bulldozer/app_builder.rb', line 112
def enable_rack_deflater
configure_environment "production", "config.middleware.use Rack::Deflater"
end
|
#gemfile ⇒ Object
28
29
30
|
# File 'lib/bulldozer/app_builder.rb', line 28
def gemfile
template "Gemfile.erb", "Gemfile"
end
|
#gitignore ⇒ Object
24
25
26
|
# File 'lib/bulldozer/app_builder.rb', line 24
def gitignore
copy_file "bulldozer_gitignore", ".gitignore"
end
|
#provide_setup_script ⇒ Object
77
78
79
80
|
# File 'lib/bulldozer/app_builder.rb', line 77
def provide_setup_script
template "bin_setup", "bin/setup", force: true
run "chmod a+x bin/setup"
end
|
#raise_on_delivery_errors ⇒ Object
48
49
50
51
|
# File 'lib/bulldozer/app_builder.rb', line 48
def raise_on_delivery_errors
replace_in_file 'config/environments/development.rb',
'raise_delivery_errors = false', 'raise_delivery_errors = true'
end
|
#raise_on_missing_assets_in_test ⇒ Object
44
45
46
|
# File 'lib/bulldozer/app_builder.rb', line 44
def raise_on_missing_assets_in_test
configure_environment "test", "config.assets.raise_runtime_errors = true"
end
|
#raise_on_unpermitted_parameters ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/bulldozer/app_builder.rb', line 61
def raise_on_unpermitted_parameters
config = "config.action_controller.action_on_unpermitted_parameters = :raise\n RUBY\n\n inject_into_class \"config/application.rb\", \"Application\", config\nend\n"
|
#readme ⇒ Object
20
21
22
|
# File 'lib/bulldozer/app_builder.rb', line 20
def readme
template 'README.md.erb', 'README.md'
end
|
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
# File 'lib/bulldozer/app_builder.rb', line 270
def
config_files = [
"application.rb",
"environment.rb",
"environments/development.rb",
"environments/production.rb",
"environments/test.rb",
]
config_files.each do |config_file|
path = File.join(destination_root, "config/#{config_file}")
accepted_content = File.readlines(path).reject do |line|
line =~ /^.*#.*$/ || line =~ /^$\n/
end
File.open(path, "w") do |file|
accepted_content.each { |line| file.puts line }
end
end
end
|
292
293
294
295
296
|
# File 'lib/bulldozer/app_builder.rb', line 292
def
replace_in_file 'config/routes.rb',
/Rails\.application\.routes\.draw do.*end/m,
"Rails.application.routes.draw do\nend"
end
|
#replace_default_puma_configuration ⇒ Object
193
194
195
|
# File 'lib/bulldozer/app_builder.rb', line 193
def replace_default_puma_configuration
copy_file "puma.rb", "config/puma.rb", force: true
end
|
#replace_gemfile(path) ⇒ Object
153
154
155
156
157
158
159
160
161
|
# File 'lib/bulldozer/app_builder.rb', line 153
def replace_gemfile(path)
template 'Gemfile.erb', 'Gemfile', force: true do |content|
if path
content.gsub(%r{gem .bulldozer.}) { |s| %{#{s}, path: "#{path}"} }
else
content
end
end
end
|
#ruby_version ⇒ Object
163
164
165
|
# File 'lib/bulldozer/app_builder.rb', line 163
def ruby_version
create_file '.ruby-version', "#{Bulldozer::RUBY_VERSION}\n"
end
|
#set_test_delivery_method ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/bulldozer/app_builder.rb', line 53
def set_test_delivery_method
inject_into_file(
"config/environments/development.rb",
"\n config.action_mailer.delivery_method = :file",
after: "config.action_mailer.raise_delivery_errors = true",
)
end
|
#set_up_forego ⇒ Object
197
198
199
|
# File 'lib/bulldozer/app_builder.rb', line 197
def set_up_forego
copy_file "Procfile", "Procfile"
end
|
#setup_asset_host ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/bulldozer/app_builder.rb', line 116
def setup_asset_host
replace_in_file 'config/environments/production.rb',
"# config.action_controller.asset_host = 'http://assets.example.com'",
'config.action_controller.asset_host = ENV.fetch("ASSET_HOST", ENV.fetch("APPLICATION_HOST"))'
if File.exist?("config/initializers/assets.rb")
replace_in_file 'config/initializers/assets.rb',
"config.assets.version = '1.0'",
'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")'
end
config = "config.public_file_server.headers = {\n\"Cache-Control\" => \"public, max-age=31557600\",\n }\n EOD\n\n configure_environment(\"production\", config)\nend\n"
|
#setup_bundler_audit ⇒ Object
240
241
242
243
|
# File 'lib/bulldozer/app_builder.rb', line 240
def setup_bundler_audit
copy_file "bundler_audit.rake", "lib/tasks/bundler_audit.rake"
append_file "Rakefile", %{\ntask default: "bundle:audit"\n}
end
|
#setup_default_directories ⇒ Object
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/bulldozer/app_builder.rb', line 201
def setup_default_directories
[
'app/views/pages',
'spec/lib',
'spec/controllers',
'spec/helpers',
'spec/support/matchers',
'spec/support/mixins',
'spec/support/shared_examples'
].each do |dir|
empty_directory_with_keep_file dir
end
end
|
#setup_default_rake_task ⇒ Object
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
# File 'lib/bulldozer/app_builder.rb', line 298
def setup_default_rake_task
append_file 'Rakefile' do
"task(:default).clear\ntask default: [:spec]\n\nif defined? RSpec\n task(:spec).clear\n RSpec::Core::RakeTask.new(:spec) do |t|\nt.verbose = false\n end\nend\n EOS\n end\nend\n"
|
#setup_rack_mini_profiler ⇒ Object
37
38
39
40
41
42
|
# File 'lib/bulldozer/app_builder.rb', line 37
def setup_rack_mini_profiler
copy_file(
"rack_mini_profiler.rb",
"config/initializers/rack_mini_profiler.rb",
)
end
|
#setup_secret_token ⇒ Object
136
137
138
|
# File 'lib/bulldozer/app_builder.rb', line 136
def setup_secret_token
template 'secrets.yml', 'config/secrets.yml', force: true
end
|
#setup_spring ⇒ Object
245
246
247
|
# File 'lib/bulldozer/app_builder.rb', line 245
def setup_spring
bundle_command "exec spring binstub --all"
end
|
#use_postgres_config_template ⇒ Object
144
145
146
147
|
# File 'lib/bulldozer/app_builder.rb', line 144
def use_postgres_config_template
template 'postgresql_database.yml.erb', 'config/database.yml',
force: true
end
|