Class: Suspenders::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Suspenders::AppBuilder
show all
- Extended by:
- Forwardable
- Includes:
- Actions
- Defined in:
- lib/suspenders/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
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/suspenders/app_builder.rb', line 176
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
|
167
168
169
|
# File 'lib/suspenders/app_builder.rb', line 167
def configure_action_mailer_in_specs
copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb'
end
|
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/suspenders/app_builder.rb', line 219
def configure_automatic_deployment
deploy_command = <<-YML.strip_heredoc
deployment:
staging:
branch: master
commands:
- bin/deploy staging
YML
append_file "circle.yml", deploy_command
end
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/suspenders/app_builder.rb', line 77
def configure_generators
config = <<-RUBY
config.generators do |generate|
generate.helper false
generate.javascripts false
generate.request_specs false
generate.routing_specs false
generate.stylesheets false
generate.test_framework :rspec
generate.view_specs false
end
RUBY
inject_into_class 'config/application.rb', 'Application', config
end
|
162
163
164
165
|
# File 'lib/suspenders/app_builder.rb', line 162
def configure_i18n_for_missing_translations
raise_on_missing_translations_in("development")
raise_on_missing_translations_in("test")
end
|
95
96
97
|
# File 'lib/suspenders/app_builder.rb', line 95
def configure_local_mail
copy_file "email.rb", "config/initializers/email.rb"
end
|
64
65
66
67
68
69
70
|
# File 'lib/suspenders/app_builder.rb', line 64
def configure_quiet_assets
config = <<-RUBY
config.assets.quiet = true
RUBY
inject_into_class "config/application.rb", "Application", config
end
|
171
172
173
174
|
# File 'lib/suspenders/app_builder.rb', line 171
def configure_time_formats
remove_file "config/locales/en.yml"
template "config_locales_en.yml.erb", "config/locales/en.yml"
end
|
#copy_dotfiles ⇒ Object
210
211
212
|
# File 'lib/suspenders/app_builder.rb', line 210
def copy_dotfiles
directory("dotfiles", ".")
end
|
#copy_miscellaneous_files ⇒ Object
244
245
246
247
|
# File 'lib/suspenders/app_builder.rb', line 244
def copy_miscellaneous_files
copy_file "errors.rb", "config/initializers/errors.rb"
copy_file "json_encoding.rb", "config/initializers/json_encoding.rb"
end
|
#create_database ⇒ Object
144
145
146
|
# File 'lib/suspenders/app_builder.rb', line 144
def create_database
bundle_command "exec rails db:create db:migrate"
end
|
#create_github_repo(repo_name) ⇒ Object
231
232
233
|
# File 'lib/suspenders/app_builder.rb', line 231
def create_github_repo(repo_name)
run "hub create #{repo_name}"
end
|
#create_heroku_apps(flags) ⇒ Object
214
215
216
217
|
# File 'lib/suspenders/app_builder.rb', line 214
def create_heroku_apps(flags)
create_staging_heroku_app(flags)
create_production_heroku_app(flags)
end
|
#customize_error_pages ⇒ Object
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
# File 'lib/suspenders/app_builder.rb', line 249
def customize_error_pages
meta_tags =<<-EOS
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1" />
EOS
%w(500 404 422).each do |page|
path = "public/#{page}.html"
if File.exist?(path)
inject_into_file path, meta_tags, after: "<head>\n"
replace_in_file path, /<!--.+-->\n/, ''
end
end
end
|
#disallow_wrapping_parameters ⇒ Object
135
136
137
|
# File 'lib/suspenders/app_builder.rb', line 135
def disallow_wrapping_parameters
remove_file "config/initializers/wrap_parameters.rb"
end
|
#enable_rack_canonical_host ⇒ Object
99
100
101
102
103
104
105
|
# File 'lib/suspenders/app_builder.rb', line 99
def enable_rack_canonical_host
config = <<-RUBY
config.middleware.use Rack::CanonicalHost, ENV.fetch("APPLICATION_HOST")
RUBY
configure_environment "production", config
end
|
#enable_rack_deflater ⇒ Object
107
108
109
|
# File 'lib/suspenders/app_builder.rb', line 107
def enable_rack_deflater
configure_environment "production", "config.middleware.use Rack::Deflater"
end
|
#gemfile ⇒ Object
28
29
30
|
# File 'lib/suspenders/app_builder.rb', line 28
def gemfile
template "Gemfile.erb", "Gemfile"
end
|
#gitignore ⇒ Object
24
25
26
|
# File 'lib/suspenders/app_builder.rb', line 24
def gitignore
copy_file "suspenders_gitignore", ".gitignore"
end
|
#provide_setup_script ⇒ Object
72
73
74
75
|
# File 'lib/suspenders/app_builder.rb', line 72
def provide_setup_script
template "bin_setup", "bin/setup", force: true
run "chmod a+x bin/setup"
end
|
#raise_on_delivery_errors ⇒ Object
43
44
45
46
|
# File 'lib/suspenders/app_builder.rb', line 43
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
39
40
41
|
# File 'lib/suspenders/app_builder.rb', line 39
def raise_on_missing_assets_in_test
configure_environment "test", "config.assets.raise_runtime_errors = true"
end
|
#raise_on_unpermitted_parameters ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/suspenders/app_builder.rb', line 56
def raise_on_unpermitted_parameters
config = <<-RUBY
config.action_controller.action_on_unpermitted_parameters = :raise
RUBY
inject_into_class "config/application.rb", "Application", config
end
|
#readme ⇒ Object
20
21
22
|
# File 'lib/suspenders/app_builder.rb', line 20
def readme
template 'README.md.erb', 'README.md'
end
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
# File 'lib/suspenders/app_builder.rb', line 264
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
|
286
287
288
289
290
|
# File 'lib/suspenders/app_builder.rb', line 286
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
188
189
190
|
# File 'lib/suspenders/app_builder.rb', line 188
def replace_default_puma_configuration
copy_file "puma.rb", "config/puma.rb", force: true
end
|
#replace_gemfile(path) ⇒ Object
148
149
150
151
152
153
154
155
156
|
# File 'lib/suspenders/app_builder.rb', line 148
def replace_gemfile(path)
template 'Gemfile.erb', 'Gemfile', force: true do |content|
if path
content.gsub(%r{gem .suspenders.}) { |s| %{#{s}, path: "#{path}"} }
else
content
end
end
end
|
#ruby_version ⇒ Object
158
159
160
|
# File 'lib/suspenders/app_builder.rb', line 158
def ruby_version
create_file '.ruby-version', "#{Suspenders::RUBY_VERSION}\n"
end
|
#set_test_delivery_method ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/suspenders/app_builder.rb', line 48
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
192
193
194
|
# File 'lib/suspenders/app_builder.rb', line 192
def set_up_forego
copy_file "Procfile", "Procfile"
end
|
#setup_asset_host ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/suspenders/app_builder.rb', line 111
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 = <<-EOD
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=31557600",
}
EOD
configure_environment("production", config)
end
|
#setup_bundler_audit ⇒ Object
235
236
237
238
|
# File 'lib/suspenders/app_builder.rb', line 235
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
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'lib/suspenders/app_builder.rb', line 196
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
# File 'lib/suspenders/app_builder.rb', line 292
def setup_default_rake_task
append_file 'Rakefile' do
<<-EOS
task(:default).clear
task default: [:spec]
if defined? RSpec
task(:spec).clear
RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = false
end
end
EOS
end
end
|
#setup_rack_mini_profiler ⇒ Object
32
33
34
35
36
37
|
# File 'lib/suspenders/app_builder.rb', line 32
def setup_rack_mini_profiler
copy_file(
"rack_mini_profiler.rb",
"config/initializers/rack_mini_profiler.rb",
)
end
|
#setup_secret_token ⇒ Object
131
132
133
|
# File 'lib/suspenders/app_builder.rb', line 131
def setup_secret_token
template 'secrets.yml', 'config/secrets.yml', force: true
end
|
#setup_spring ⇒ Object
240
241
242
|
# File 'lib/suspenders/app_builder.rb', line 240
def setup_spring
bundle_command "exec spring binstub --all"
end
|
#use_postgres_config_template ⇒ Object
139
140
141
142
|
# File 'lib/suspenders/app_builder.rb', line 139
def use_postgres_config_template
template 'postgresql_database.yml.erb', 'config/database.yml',
force: true
end
|