Class: Yupi::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Yupi::AppBuilder
show all
- Includes:
- Actions
- Defined in:
- lib/yupi/app_builder.rb
Instance Method Summary
collapse
Methods included from Actions
#action_mailer_host, #configure_application_file, #configure_environment, #replace_in_file
Instance Method Details
#add_root_route ⇒ Object
320
321
322
|
# File 'lib/yupi/app_builder.rb', line 320
def add_root_route
route "root 'high_voltage/pages#show', id: 'home'"
end
|
232
233
234
235
236
|
# File 'lib/yupi/app_builder.rb', line 232
def configure_action_mailer
action_mailer_host "development", %{"localhost:3000"}
action_mailer_host "test", %{"www.example.com"}
action_mailer_host "production", %{ENV.fetch("HOST")}
end
|
208
209
210
|
# File 'lib/yupi/app_builder.rb', line 208
def configure_action_mailer_in_specs
copy_file 'spec/support/action_mailer.rb', 'spec/support/action_mailer.rb'
end
|
238
239
240
241
242
243
|
# File 'lib/yupi/app_builder.rb', line 238
def configure_active_job
configure_application_file(
"config.active_job.queue_adapter = :delayed_job"
)
configure_environment "test", "config.active_job.queue_adapter = :inline"
end
|
204
205
206
|
# File 'lib/yupi/app_builder.rb', line 204
def configure_background_jobs_for_rspec
run 'rails g delayed_job:active_record'
end
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/yupi/app_builder.rb', line 45
def configure_generators
config = <<-RUBY
config.generators do |generate|
generate.helper false
generate.javascript_engine 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
|
194
195
196
197
|
# File 'lib/yupi/app_builder.rb', line 194
def configure_i18n_for_missing_translations
raise_on_missing_translations_in("development")
raise_on_missing_translations_in("test")
end
|
190
191
192
|
# File 'lib/yupi/app_builder.rb', line 190
def configure_i18n_for_test_environment
copy_file "spec/support/i18n.rb", "spec/support/i18n.rb"
end
|
199
200
201
202
|
# File 'lib/yupi/app_builder.rb', line 199
def configure_i18n_tasks
run "cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/"
copy_file "config/i18n_tasks.yml", "config/i18n-tasks.yml"
end
|
222
223
224
225
|
# File 'lib/yupi/app_builder.rb', line 222
def configure_mail_interceptor
copy_file 'config/initializers/mail_interceptor.rb',
'config/initializers/mail_interceptor.rb'
end
|
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/yupi/app_builder.rb', line 71
def configure_mailsocio
config = <<-RUBY
config.action_mailer.delivery_method = :mailsocio
config.action_mailer.smtp_settings = {
account_id: ENV.fetch("MAILSOCIO_ACCOUNT_ID"),
api_key: ENV.fetch("MAILSOCIO_API_KEY")
}
RUBY
inject_into_file 'config/environments/production.rb', config,
:after => 'config.action_mailer.raise_delivery_errors = false'
end
|
67
68
69
|
# File 'lib/yupi/app_builder.rb', line 67
def configure_newrelic
template 'config/newrelic.yml.erb', 'config/newrelic.yml'
end
|
257
258
259
260
|
# File 'lib/yupi/app_builder.rb', line 257
def configure_puma
bundle_command 'binstub puma'
remove_file 'bin/pumactl'
end
|
217
218
219
220
|
# File 'lib/yupi/app_builder.rb', line 217
def configure_rack_timeout
copy_file 'config/initializers/rack_timeout.rb',
'config/initializers/rack_timeout.rb'
end
|
183
184
185
186
187
188
|
# File 'lib/yupi/app_builder.rb', line 183
def configure_rspec
remove_file "spec/rails_helper.rb"
remove_file "spec/spec_helper.rb"
copy_file "spec/rails_helper.rb", "spec/rails_helper.rb"
copy_file "spec/spec_helper.rb", "spec/spec_helper.rb"
end
|
227
228
229
230
|
# File 'lib/yupi/app_builder.rb', line 227
def configure_simple_form
bundle_command "exec rails generate simple_form:install --bootstrap > /dev/null 2>&1"
end
|
173
174
175
176
177
178
179
180
181
|
# File 'lib/yupi/app_builder.rb', line 173
def configure_spec_support_features
empty_directory_with_keep_file 'spec/lib'
empty_directory_with_keep_file 'spec/features'
empty_directory_with_keep_file 'spec/support/matchers'
empty_directory_with_keep_file 'spec/support/mixins'
empty_directory_with_keep_file 'spec/support/shared_examples'
empty_directory_with_keep_file 'spec/support/features'
end
|
212
213
214
215
|
# File 'lib/yupi/app_builder.rb', line 212
def configure_time_formats
remove_file "config/locales/en.yml"
template "config/locales_en.yml.erb", "config/locales/en.yml"
end
|
#copy_miscellaneous_files ⇒ Object
296
297
298
299
|
# File 'lib/yupi/app_builder.rb', line 296
def copy_miscellaneous_files
copy_file "config/initializers/errors.rb", "config/initializers/errors.rb"
copy_file "config/initializers/json_encoding.rb", "config/initializers/json_encoding.rb"
end
|
#create_application_layout ⇒ Object
145
146
147
148
149
|
# File 'lib/yupi/app_builder.rb', line 145
def create_application_layout
remove_file 'app/views/layouts/application.html.erb'
copy_file 'views/layouts/application.html.haml',
'app/views/layouts/application.html.haml'
end
|
#create_database ⇒ Object
156
157
158
|
# File 'lib/yupi/app_builder.rb', line 156
def create_database
bundle_command 'exec rake db:create db:migrate'
end
|
#create_home_page ⇒ Object
140
141
142
143
|
# File 'lib/yupi/app_builder.rb', line 140
def create_home_page
copy_file 'views/pages/home.html.haml',
'app/views/pages/home.html.haml'
end
|
#create_partials ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/yupi/app_builder.rb', line 123
def create_partials
empty_directory 'app/views/application'
copy_file 'views/application/_flashes.html.haml',
'app/views/application/_flashes.html.haml'
copy_file 'views/application/_javascript.html.haml',
'app/views/application/_javascript.html.haml'
copy_file 'views/application/_navigation.html.haml',
'app/views/application/_navigation.html.haml'
copy_file 'views/application/_navigation_links.html.haml',
'app/views/application/_navigation_links.html.haml'
copy_file 'views/application/_analytics.html.haml',
'app/views/application/_analytics.html.haml'
copy_file 'views/application/_footer.html.haml',
'app/views/application/_footer.html.haml'
end
|
#customize_error_pages ⇒ Object
301
302
303
304
305
306
307
308
309
310
311
312
|
# File 'lib/yupi/app_builder.rb', line 301
def customize_error_pages
meta_tags =<<-EOS
<meta charset="utf-8" />
<meta name="ROBOTS" content="NOODP" />
<meta name="viewport" content="initial-scale=1" />
EOS
%w(500 404 422).each do |page|
inject_into_file "public/#{page}.html", meta_tags, :after => "<head>\n"
replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
end
end
|
#disable_xml_params ⇒ Object
324
325
326
327
|
# File 'lib/yupi/app_builder.rb', line 324
def disable_xml_params
copy_file 'config/initializers/disable_xml_params.rb',
'config/initializers/disable_xml_params.rb'
end
|
#disallow_wrapping_parameters ⇒ Object
119
120
121
|
# File 'lib/yupi/app_builder.rb', line 119
def disallow_wrapping_parameters
remove_file "config/initializers/wrap_parameters.rb"
end
|
#enable_database_cleaner ⇒ Object
169
170
171
|
# File 'lib/yupi/app_builder.rb', line 169
def enable_database_cleaner
copy_file 'spec/support/database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
end
|
#enable_rack_deflater ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/yupi/app_builder.rb', line 85
def enable_rack_deflater
config = <<-RUBY
# Enable deflate / gzip compression of controller-generated responses
config.middleware.use Rack::Deflater
RUBY
inject_into_file(
"config/environments/production.rb",
config,
after: serve_static_files_line
)
end
|
#fix_i18n_deprecation_warning ⇒ Object
245
246
247
248
249
250
251
|
# File 'lib/yupi/app_builder.rb', line 245
def fix_i18n_deprecation_warning
config = <<-RUBY
config.i18n.enforce_available_locales = true
RUBY
inject_into_class 'config/application.rb', 'Application', config
end
|
#generate_rspec ⇒ Object
253
254
255
|
# File 'lib/yupi/app_builder.rb', line 253
def generate_rspec
generate 'rspec:install'
end
|
#gitignore_files ⇒ Object
282
283
284
285
|
# File 'lib/yupi/app_builder.rb', line 282
def gitignore_files
remove_file '.gitignore'
copy_file 'dot_gitignore', '.gitignore'
end
|
#init_git ⇒ Object
287
288
289
|
# File 'lib/yupi/app_builder.rb', line 287
def init_git
run 'git init'
end
|
#provide_dev_prime_task ⇒ Object
41
42
43
|
# File 'lib/yupi/app_builder.rb', line 41
def provide_dev_prime_task
copy_file 'tasks/development_seeds.rake', 'lib/tasks/development_seeds.rake'
end
|
#provide_setup_script ⇒ Object
36
37
38
39
|
# File 'lib/yupi/app_builder.rb', line 36
def provide_setup_script
template "bin/setup.erb", "bin/setup", force: true
run "chmod a+x bin/setup"
end
|
#raise_on_delivery_errors ⇒ Object
9
10
11
12
|
# File 'lib/yupi/app_builder.rb', line 9
def raise_on_delivery_errors
replace_in_file 'config/environments/development.rb',
'raise_delivery_errors = false', 'raise_delivery_errors = true'
end
|
#raise_on_unpermitted_parameters ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/yupi/app_builder.rb', line 28
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
5
6
7
|
# File 'lib/yupi/app_builder.rb', line 5
def readme
template 'README.md.erb', 'README.md'
end
|
314
315
316
317
318
|
# File 'lib/yupi/app_builder.rb', line 314
def
replace_in_file 'config/routes.rb',
/Rails\.application\.routes\.draw do.*end/m,
"Rails.application.routes.draw do\nend"
end
|
#replace_gemfile ⇒ Object
160
161
162
163
|
# File 'lib/yupi/app_builder.rb', line 160
def replace_gemfile
remove_file 'Gemfile'
template 'Gemfile.erb', 'Gemfile'
end
|
#run_bin_setup ⇒ Object
345
346
347
|
# File 'lib/yupi/app_builder.rb', line 345
def run_bin_setup
run "./bin/setup"
end
|
#set_ruby_to_version_being_used ⇒ Object
165
166
167
|
# File 'lib/yupi/app_builder.rb', line 165
def set_ruby_to_version_being_used
create_file '.ruby-version', "#{Yupi::RUBY_VERSION}\n"
end
|
#set_test_delivery_method ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/yupi/app_builder.rb', line 14
def set_test_delivery_method
config = <<-RUBY
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
RUBY
inject_into_file(
"config/environments/development.rb",
config,
after: "config.action_mailer.raise_delivery_errors = true",
)
end
|
#set_up_factory_girl_for_rspec ⇒ Object
63
64
65
|
# File 'lib/yupi/app_builder.rb', line 63
def set_up_factory_girl_for_rspec
copy_file 'spec/support/factory_girl_rspec.rb', 'spec/support/factory_girl.rb'
end
|
#setup_asset_host ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/yupi/app_builder.rb', line 99
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("HOST"))'
replace_in_file 'config/initializers/assets.rb',
"config.assets.version = '1.0'",
'config.assets.version = ENV.fetch("ASSETS_VERSION", "1.0")'
inject_into_file(
"config/environments/production.rb",
' config.static_cache_control = "public, max-age=#{1.year.to_i}"',
after: serve_static_files_line
)
end
|
#setup_bundler_audit ⇒ Object
291
292
293
294
|
# File 'lib/yupi/app_builder.rb', line 291
def setup_bundler_audit
copy_file "tasks/bundler_audit.rake", "lib/tasks/bundler_audit.rake"
append_file "Rakefile", %{\ntask default: "bundler:audit"\n}
end
|
#setup_default_rake_task ⇒ Object
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
# File 'lib/yupi/app_builder.rb', line 329
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_figaro ⇒ Object
266
267
268
|
# File 'lib/yupi/app_builder.rb', line 266
def setup_figaro
copy_file 'config/application.yml.sample', 'config/application.yml.sample'
end
|
#setup_foreman ⇒ Object
262
263
264
|
# File 'lib/yupi/app_builder.rb', line 262
def setup_foreman
copy_file 'Procfile', 'Procfile'
end
|
#setup_javascripts ⇒ Object
276
277
278
279
280
|
# File 'lib/yupi/app_builder.rb', line 276
def setup_javascripts
remove_file 'app/assets/javascripts/application.js'
copy_file 'assets/application.js',
'app/assets/javascripts/application.js'
end
|
#setup_secret_token ⇒ Object
115
116
117
|
# File 'lib/yupi/app_builder.rb', line 115
def setup_secret_token
template 'config/rails_secrets.yml', 'config/secrets.yml', force: true
end
|
#setup_stylesheets ⇒ Object
270
271
272
273
274
|
# File 'lib/yupi/app_builder.rb', line 270
def setup_stylesheets
remove_file 'app/assets/stylesheets/application.css'
copy_file 'assets/application.css.scss',
'app/assets/stylesheets/application.css.scss'
end
|
#use_postgres_config_template ⇒ Object
151
152
153
154
|
# File 'lib/yupi/app_builder.rb', line 151
def use_postgres_config_template
template 'config/postgresql_database.yml.erb', 'config/database.yml',
force: true
end
|