kratos 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +21 -0
  7. data/README.md +24 -0
  8. data/bin/kratos +18 -0
  9. data/bin/rake +16 -0
  10. data/bin/rspec +16 -0
  11. data/bin/setup +14 -0
  12. data/kratos.gemspec +30 -0
  13. data/lib/kratos/actions.rb +31 -0
  14. data/lib/kratos/app_builder.rb +468 -0
  15. data/lib/kratos/generators/app_generator.rb +164 -0
  16. data/lib/kratos/version.rb +6 -0
  17. data/lib/kratos.rb +4 -0
  18. data/templates/Capfile +15 -0
  19. data/templates/Gemfile.erb +67 -0
  20. data/templates/Procfile +2 -0
  21. data/templates/README.md.erb +29 -0
  22. data/templates/_javascript.html.erb +10 -0
  23. data/templates/acceptance_helpers_rspec.rb +18 -0
  24. data/templates/action_mailer.rb +5 -0
  25. data/templates/application.scss +4 -0
  26. data/templates/bin_setup +25 -0
  27. data/templates/brakeman.rake +9 -0
  28. data/templates/bundler_audit.rake +12 -0
  29. data/templates/cap_environment.rb +1 -0
  30. data/templates/capybara_poltergeist.rb +17 -0
  31. data/templates/circle.yml.erb +9 -0
  32. data/templates/config_locales_en_datetime.yml +107 -0
  33. data/templates/config_locales_en_messages.yml.erb +3 -0
  34. data/templates/config_locales_pt-BR_datetime.yml +108 -0
  35. data/templates/config_locales_pt-BR_messages.yml.erb +4 -0
  36. data/templates/database_cleaner_rspec.rb +21 -0
  37. data/templates/deploy.rake +28 -0
  38. data/templates/deploy_config.rb.erb +33 -0
  39. data/templates/dev.rake +12 -0
  40. data/templates/disable_xml_params.rb +1 -0
  41. data/templates/dotfiles/.ctags +2 -0
  42. data/templates/dotfiles/.gitignore +14 -0
  43. data/templates/dotfiles/.sample.application.yml +15 -0
  44. data/templates/errors.rb +34 -0
  45. data/templates/factory_girl_rspec.rb +3 -0
  46. data/templates/foreman.rake +39 -0
  47. data/templates/i18n-tasks.yml +22 -0
  48. data/templates/i18n.rb +3 -0
  49. data/templates/i18n_rspec.rb +19 -0
  50. data/templates/json_encoding.rb +1 -0
  51. data/templates/kratos_layout.html.erb.erb +20 -0
  52. data/templates/lograge.rb +14 -0
  53. data/templates/postgresql_database.yml.erb +22 -0
  54. data/templates/puma.rb +28 -0
  55. data/templates/rails_helper.rb +28 -0
  56. data/templates/redis.rb +10 -0
  57. data/templates/rspec_api_documentation_rspec.rb.erb +33 -0
  58. data/templates/rubocop.rake +4 -0
  59. data/templates/rubocop.yml +40 -0
  60. data/templates/schedule.rb +8 -0
  61. data/templates/secrets.yml +14 -0
  62. data/templates/shoulda_matchers_config_rspec.rb +6 -0
  63. data/templates/sidekiq.yml +4 -0
  64. data/templates/sidekiq_rspec.yml +10 -0
  65. data/templates/sidekiq_security.rb +6 -0
  66. data/templates/smtp.rb +9 -0
  67. data/templates/spec_helper.rb +31 -0
  68. data/templates/staging.rb +5 -0
  69. data/templates/timezones.rb +26 -0
  70. metadata +145 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3bf3258c4f75a7e9173e69b697a57132ea148e5f
4
+ data.tar.gz: 9eaaff5b95d9fd80e7f50af256044862f825908d
5
+ SHA512:
6
+ metadata.gz: 7200c9d126bac15d7c6ce6df689134dce2d785348f556357af26f3151d368afa93000fdf6530931612e32bd627727e030697e7446fe074807b90d2a7a1c27dbc
7
+ data.tar.gz: 4e262bc5e8209e09e1ea69ced3eaf1060e074fa1260e0f48e0951ac1bf60378dd2cbde580ea3a2a5b43089f537c6944905f5ab0a4dfcc54e7652321da8923a53
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ *.swp
3
+ Gemfile.lock
4
+ /.bundle
5
+ /tmp
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm: 2.3.0
3
+ cache: bundler
4
+ sudo: false
5
+ before_install:
6
+ - "echo '--colour' > ~/.rspec"
7
+ - git config --global user.name 'Travis CI'
8
+ - git config --global user.email 'travis-ci@example.com'
9
+ install: bundle install
10
+ notifications:
11
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2008-2015 thoughtbot, inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Kratos
2
+
3
+ Kratos is a rails application generator based on
4
+ [Suspenders](https://github.com/thoughtbot/suspenders).
5
+
6
+ ## Installation
7
+
8
+ First install the kratos gem:
9
+
10
+ gem install kratos
11
+
12
+ Then run:
13
+
14
+ kratos projectname
15
+
16
+ This will create a Rails app in `projectname` using the latest version of Rails.
17
+
18
+ ## License
19
+
20
+ Suspenders is Copyright © 2008-2015 thoughtbot.
21
+ It is free software,
22
+ and may be redistributed under the terms specified in the [LICENSE] file.
23
+
24
+ [LICENSE]: LICENSE
data/bin/kratos ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ source_path = (Pathname.new(__FILE__).dirname + '../lib').expand_path
5
+ $LOAD_PATH << source_path
6
+
7
+ require 'kratos'
8
+
9
+ if ['-v', '--version'].include? ARGV[0]
10
+ puts Kratos::VERSION
11
+ exit 0
12
+ end
13
+
14
+ templates_root = File.expand_path(File.join('..', 'templates'), File.dirname(__FILE__))
15
+ Kratos::AppGenerator.source_root templates_root
16
+ Kratos::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
17
+
18
+ Kratos::AppGenerator.start
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/setup ADDED
@@ -0,0 +1,14 @@
1
+ #!/bin/sh
2
+
3
+ # Run this script immediately after cloning the codebase.
4
+
5
+ # Exit if any subcommand fails
6
+ set -e
7
+
8
+ # Set up Ruby dependencies via Bundler
9
+ bundle install
10
+
11
+ # Add binstubs to PATH in ~/.zshenv like this:
12
+ # export PATH=".git/safe/../../bin:$PATH"
13
+ mkdir -p .git/safe
14
+ mkdir -p tmp/pids
data/kratos.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+ require 'kratos/version'
4
+ require 'date'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.required_ruby_version = ">= #{Kratos::RUBY_VERSION}"
8
+ s.authors = ['jaisonerick']
9
+ s.date = Date.today.strftime('%Y-%m-%d')
10
+
11
+ s.description = <<-HERE
12
+ Kratos is a rails project generator that is ready for deployment with
13
+ capistrano. Based on thoughtbot's "suspenders".
14
+ HERE
15
+
16
+ s.email = 'jaisonreis@gmail.com'
17
+ s.executables = ['kratos']
18
+ s.extra_rdoc_files = %w(README.md)
19
+ s.files = `git ls-files`.split("\n")
20
+ s.homepage = 'http://github.com/jaisonerick/kratos'
21
+ s.license = 'MIT'
22
+ s.name = 'kratos'
23
+ s.rdoc_options = ['--charset=UTF-8']
24
+ s.require_paths = ['lib']
25
+ s.summary = 'A rails project generator based on thoughtbot\'s suspenders.'
26
+ s.version = Kratos::VERSION
27
+
28
+ s.add_dependency 'bundler', '~> 1.3'
29
+ s.add_dependency 'rails', Kratos::RAILS_VERSION
30
+ end
@@ -0,0 +1,31 @@
1
+ module Kratos
2
+ module Actions
3
+ def replace_in_file(relative_path, find, replace)
4
+ path = File.join(destination_root, relative_path)
5
+ contents = IO.read(path)
6
+ unless contents.gsub!(find, replace)
7
+ fail "#{find.inspect} not found in #{relative_path}"
8
+ end
9
+ File.open(path, 'w') { |file| file.write(contents) }
10
+ end
11
+
12
+ def action_mailer_host(rails_env, host)
13
+ config = "config.action_mailer.default_url_options = { host: #{host} }"
14
+ configure_environment(rails_env, config)
15
+
16
+ inject_into_file(
17
+ "config/environments/#{rails_env}.rb",
18
+ "\nRails.application.routes.default_url_options = { host: #{host} }",
19
+ after: "\nend"
20
+ )
21
+ end
22
+
23
+ def configure_environment(rails_env, config)
24
+ inject_into_file(
25
+ "config/environments/#{rails_env}.rb",
26
+ "\n\n #{config}",
27
+ before: "\nend"
28
+ )
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,468 @@
1
+ class AppBuilder < Rails::AppBuilder
2
+ include Kratos::Actions
3
+
4
+ def replace_gemfile
5
+ remove_file 'Gemfile'
6
+ template 'Gemfile.erb', 'Gemfile'
7
+ end
8
+
9
+ def set_ruby_to_version_being_used
10
+ create_file '.ruby-version', "#{Kratos::RUBY_VERSION}\n"
11
+ end
12
+
13
+ def readme
14
+ template 'README.md.erb', 'README.md'
15
+ end
16
+
17
+ def raise_on_missing_assets_in_test
18
+ inject_into_file(
19
+ 'config/environments/test.rb',
20
+ "\n config.assets.raise_runtime_errors = true",
21
+ after: 'Rails.application.configure do'
22
+ )
23
+ end
24
+
25
+ def raise_on_delivery_errors
26
+ replace_in_file 'config/environments/development.rb',
27
+ 'raise_delivery_errors = false',
28
+ 'raise_delivery_errors = true'
29
+ end
30
+
31
+ def set_test_delivery_method
32
+ inject_into_file(
33
+ 'config/environments/development.rb',
34
+ "\n config.action_mailer.delivery_method = :test",
35
+ after: 'config.action_mailer.raise_delivery_errors = true'
36
+ )
37
+ end
38
+
39
+ def add_bullet_gem_configuration
40
+ config = <<-RUBY
41
+ config.after_initialize do
42
+ Bullet.enable = true
43
+ Bullet.bullet_logger = true
44
+ Bullet.rails_logger = true
45
+ end
46
+
47
+ RUBY
48
+
49
+ inject_into_file(
50
+ 'config/environments/development.rb',
51
+ config,
52
+ after: "config.action_mailer.raise_delivery_errors = true\n"
53
+ )
54
+ end
55
+
56
+ def raise_on_unpermitted_parameters
57
+ config = <<-RUBY
58
+ config.action_controller.action_on_unpermitted_parameters = :raise
59
+ RUBY
60
+
61
+ inject_into_class 'config/application.rb', 'Application', config
62
+ end
63
+
64
+ def provide_setup_script
65
+ template 'bin_setup', 'bin/setup', force: true
66
+ run 'chmod a+x bin/setup'
67
+ end
68
+
69
+ def provide_dev_prime_task
70
+ copy_file 'dev.rake', 'lib/tasks/dev.rake'
71
+ end
72
+
73
+ def configure_generators
74
+ config = <<-RUBY
75
+
76
+ config.generators do |generate|
77
+ generate.helper false
78
+ generate.javascript_engine false
79
+ generate.request_specs false
80
+ generate.routing_specs false
81
+ generate.stylesheets false
82
+ generate.test_framework :rspec
83
+ generate.view_specs false
84
+ end
85
+
86
+ RUBY
87
+
88
+ inject_into_class 'config/application.rb', 'Application', config
89
+ end
90
+
91
+ def configure_i18n_for_missing_translations
92
+ raise_on_missing_translations_in('development')
93
+ raise_on_missing_translations_in('test')
94
+ end
95
+
96
+ def configure_quiet_assets
97
+ config = <<-RUBY
98
+ config.quiet_assets = true
99
+ RUBY
100
+
101
+ inject_into_class 'config/application.rb', 'Application', config
102
+ end
103
+
104
+
105
+ def set_up_factory_girl_for_rspec
106
+ copy_file 'factory_girl_rspec.rb', 'spec/support/factory_girl.rb'
107
+ end
108
+
109
+ def create_factories_directory
110
+ empty_directory 'spec/factories'
111
+ end
112
+
113
+ def generate_rspec
114
+ generate 'rspec:install'
115
+ end
116
+
117
+ def configure_rspec
118
+ remove_file 'spec/rails_helper.rb'
119
+ remove_file 'spec/spec_helper.rb'
120
+ copy_file 'rails_helper.rb', 'spec/rails_helper.rb'
121
+ copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
122
+ end
123
+
124
+ def enable_database_cleaner
125
+ copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
126
+ end
127
+
128
+ def provide_shoulda_matchers_config
129
+ copy_file(
130
+ 'shoulda_matchers_config_rspec.rb',
131
+ 'spec/support/shoulda_matchers.rb'
132
+ )
133
+ end
134
+
135
+ def configure_spec_support_features
136
+ empty_directory_with_keep_file 'spec/features'
137
+ end
138
+
139
+ def configure_ci
140
+ template 'circle.yml.erb', 'circle.yml'
141
+ end
142
+
143
+ def configure_i18n_for_test_environment
144
+ copy_file 'i18n.rb', 'spec/support/i18n.rb'
145
+ end
146
+
147
+ def configure_action_mailer_in_specs
148
+ copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb'
149
+ end
150
+
151
+ def configure_capybara_poltergeist
152
+ copy_file 'capybara_poltergeist.rb', 'spec/support/capybara_poltergeist.rb'
153
+ end
154
+
155
+ def configure_rspec_api_documentation
156
+ template 'rspec_api_documentation_rspec.rb.erb', 'spec/support/rspec_api_documentation.rb'
157
+ end
158
+
159
+ def configure_acceptance_helpers
160
+ copy_file 'acceptance_helpers_rspec.rb', 'spec/support/acceptance_helpers.rb'
161
+ end
162
+
163
+ def configure_i18n_tasks
164
+ copy_file 'i18n_rspec.rb', 'spec/i18n_spec.rb'
165
+ copy_file 'i18n-tasks.yml', 'config/i18n-tasks.yml'
166
+ end
167
+
168
+ def configure_smtp
169
+ copy_file 'smtp.rb', 'config/smtp.rb'
170
+
171
+ prepend_file 'config/environments/production.rb',
172
+ %{require Rails.root.join("config/smtp")\n}
173
+
174
+ config = <<-RUBY
175
+
176
+ config.action_mailer.delivery_method = :smtp
177
+ config.action_mailer.smtp_settings = SMTP_SETTINGS
178
+ RUBY
179
+
180
+ inject_into_file 'config/environments/production.rb', config,
181
+ after: 'config.action_mailer.raise_delivery_errors = false'
182
+ end
183
+
184
+ def enable_rack_deflater
185
+ config = <<-RUBY
186
+
187
+ # Enable deflate / gzip compression of controller-generated responses
188
+ config.middleware.use Rack::Deflater
189
+ RUBY
190
+
191
+ inject_into_file(
192
+ 'config/environments/production.rb',
193
+ config,
194
+ after: serve_static_files_line
195
+ )
196
+ end
197
+
198
+ def setup_asset_host
199
+ replace_in_file 'config/environments/production.rb',
200
+ "# config.action_controller.asset_host = 'http://assets.example.com'",
201
+ 'config.action_controller.asset_host = ENV.fetch("ASSET_HOST", ENV.fetch("APPLICATION_HOST"))'
202
+
203
+ replace_in_file 'config/initializers/assets.rb',
204
+ "config.assets.version = '1.0'",
205
+ 'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")'
206
+
207
+ inject_into_file(
208
+ 'config/environments/production.rb',
209
+ ' config.static_cache_control = "public, max-age=#{1.year.to_i}"',
210
+ after: serve_static_files_line
211
+ )
212
+ end
213
+
214
+ def configure_lograge
215
+ copy_file 'lograge.rb', 'config/initializers/lograge.rb'
216
+ end
217
+
218
+ def setup_dalli_cache
219
+ inject_into_file(
220
+ 'config/environments/production.rb',
221
+ ' config.cache_store = :dalli_store',
222
+ after: "config.cache_classes = true\n"
223
+ )
224
+ end
225
+
226
+ def setup_staging_environment
227
+ staging_file = 'config/environments/staging.rb'
228
+ copy_file 'staging.rb', staging_file
229
+
230
+ config = <<-RUBY
231
+
232
+ Rails.application.configure do
233
+ # ...
234
+ end
235
+ RUBY
236
+
237
+ append_file staging_file, config
238
+ end
239
+
240
+ def setup_secret_token
241
+ template 'secrets.yml', 'config/secrets.yml', force: true
242
+ end
243
+
244
+ def create_partials_directory
245
+ empty_directory 'app/views/application'
246
+ end
247
+
248
+ def create_shared_javascripts
249
+ copy_file '_javascript.html.erb',
250
+ 'app/views/application/_javascript.html.erb'
251
+ end
252
+
253
+ def create_application_layout
254
+ template 'kratos_layout.html.erb.erb',
255
+ 'app/views/layouts/application.html.erb',
256
+ force: true
257
+ end
258
+
259
+ def copy_dotfiles
260
+ remove_file '.gitignore'
261
+ directory('dotfiles', '.')
262
+ end
263
+
264
+ def configure_action_mailer
265
+ action_mailer_host 'development', %("localhost:3000")
266
+ action_mailer_host 'test', %("www.example.com")
267
+ action_mailer_host 'production', %{ENV.fetch("APPLICATION_HOST")}
268
+ end
269
+
270
+ def configure_redis
271
+ copy_file 'redis.rb', 'config/initializers/redis.rb'
272
+ end
273
+
274
+ def configure_sidekiq
275
+ copy_file 'sidekiq.yml', 'config/sidekiq.yml'
276
+ copy_file 'sidekiq_rspec.yml', 'spec/support/sidekiq.rb'
277
+ copy_file 'sidekiq_security.rb', 'config/initializers/sidekiq.rb'
278
+ empty_directory 'tmp/pids'
279
+ end
280
+
281
+ def configure_routes
282
+ replace_in_file 'config/routes.rb',
283
+ /Rails\.application\.routes\.draw do.*end/m,
284
+ <<-EOS
285
+ Rails.application.routes.draw do
286
+ require 'sidekiq/web'
287
+ mount Sidekiq::Web => '/sidekiq'
288
+ end
289
+ EOS
290
+ end
291
+
292
+ def configure_time_formats
293
+ remove_file 'config/locales/en.yml'
294
+ copy_file 'config_locales_en_datetime.yml', 'config/locales/en.datetime.yml'
295
+ copy_file 'config_locales_pt-BR_datetime.yml', 'config/locales/pt-BR.datetime.yml'
296
+ end
297
+
298
+ def configure_i18n_messages
299
+ template 'config_locales_en_messages.yml.erb', 'config/locales/en.messages.yml'
300
+ template 'config_locales_pt-BR_messages.yml.erb', 'config/locales/pt-BR.messages.yml'
301
+ end
302
+
303
+ def configure_whenever
304
+ copy_file 'schedule.rb', 'config/schedule.rb'
305
+ end
306
+
307
+ def configure_app_services
308
+ empty_directory 'app/services'
309
+
310
+ config = <<-RUBY
311
+
312
+ config.autoload_paths += ['#\{config.root}/app/services']
313
+ RUBY
314
+
315
+ inject_into_class 'config/application.rb', 'Application', config
316
+ end
317
+
318
+ def setup_brazilian_app
319
+ config = <<-RUBY
320
+ config.time_zone = 'Brasilia'
321
+ config.i18n.default_locale = :'pt-BR'
322
+ RUBY
323
+
324
+ inject_into_class 'config/application.rb', 'Application', config
325
+
326
+ copy_file 'timezones.rb', 'config/initializers/timezones.rb'
327
+ end
328
+
329
+ def disable_xml_params
330
+ copy_file 'disable_xml_params.rb', 'config/initializers/disable_xml_params.rb'
331
+ end
332
+
333
+ def copy_miscellaneous_files
334
+ copy_file 'errors.rb', 'config/initializers/errors.rb'
335
+ copy_file 'json_encoding.rb', 'config/initializers/json_encoding.rb'
336
+ end
337
+
338
+ def fix_i18n_deprecation_warning
339
+ config = <<-RUBY
340
+ config.i18n.enforce_available_locales = false
341
+ RUBY
342
+
343
+ inject_into_class 'config/application.rb', 'Application', config
344
+ end
345
+
346
+ def setup_default_rake_task
347
+ append_file 'Rakefile' do
348
+ <<-EOS
349
+ task(:default).clear
350
+ task default: [:spec]
351
+
352
+ if defined? RSpec
353
+ task(:spec).clear
354
+ RSpec::Core::RakeTask.new(:spec) do |t|
355
+ t.verbose = false
356
+ end
357
+ end
358
+ EOS
359
+ end
360
+ end
361
+
362
+ def configure_puma
363
+ copy_file 'puma.rb', 'config/puma.rb'
364
+ end
365
+
366
+ def set_up_forego
367
+ copy_file 'Procfile', 'Procfile'
368
+ end
369
+
370
+ def customize_error_pages
371
+ meta_tags = <<-EOS
372
+ <meta charset="utf-8" />
373
+ <meta name="ROBOTS" content="NOODP" />
374
+ <meta name="viewport" content="initial-scale=1" />
375
+ EOS
376
+
377
+ %w(500 404 422).each do |page|
378
+ inject_into_file "public/#{page}.html", meta_tags, after: "<head>\n"
379
+ replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
380
+ end
381
+ end
382
+
383
+ def remove_config_comment_lines
384
+ config_files = [
385
+ 'application.rb',
386
+ 'environment.rb',
387
+ 'environments/development.rb',
388
+ 'environments/production.rb',
389
+ 'environments/test.rb'
390
+ ]
391
+
392
+ config_files.each do |config_file|
393
+ path = File.join(destination_root, "config/#{config_file}")
394
+
395
+ accepted_content = File.readlines(path).reject do |line|
396
+ line =~ /^.*#.*$/ || line =~ /^$\n/
397
+ end
398
+
399
+ File.open(path, 'w') do |file|
400
+ accepted_content.each { |line| file.puts line }
401
+ end
402
+ end
403
+ end
404
+
405
+ def setup_stylesheets
406
+ remove_file 'app/assets/stylesheets/application.css'
407
+ copy_file 'application.scss',
408
+ 'app/assets/stylesheets/application.scss'
409
+ end
410
+
411
+ def init_git
412
+ run 'git init'
413
+ end
414
+
415
+ def use_postgres_config_template
416
+ template 'postgresql_database.yml.erb', 'config/database.yml',
417
+ force: true
418
+ end
419
+
420
+ def create_database
421
+ bundle_command 'exec rake db:create db:migrate'
422
+ end
423
+
424
+ def create_capistrano_tasks
425
+ copy_file 'deploy.rake', 'lib/capistrano/tasks/deploy.rake'
426
+ copy_file 'foreman.rake', 'lib/capistrano/tasks/foreman.rake'
427
+ end
428
+
429
+ def create_capfile
430
+ copy_file 'Capfile', 'Capfile'
431
+ end
432
+
433
+ def create_capistrano_config
434
+ template 'deploy_config.rb.erb', 'config/deploy.rb'
435
+ end
436
+
437
+ def create_capistrano_config
438
+ copy_file 'cap_environment.rb', 'config/deploy/production.rb'
439
+ copy_file 'cap_environment.rb', 'config/deploy/staging.rb'
440
+ end
441
+
442
+ def setup_bundler_audit
443
+ copy_file 'bundler_audit.rake', 'lib/tasks/bundler_audit.rake'
444
+ append_file 'Rakefile', %(\ntask default: "bundler:audit"\n)
445
+ end
446
+
447
+ def setup_rubocop
448
+ copy_file 'rubocop.rake', 'lib/tasks/rubocop.rake'
449
+ append_file 'Rakefile', %(\ntask default: "rubocop"\n)
450
+ end
451
+
452
+ def setup_brakeman
453
+ copy_file 'brakeman.rake', 'lib/tasks/brakeman.rake'
454
+ append_file 'Rakefile', %(\ntask default: "brakeman:run"\n)
455
+ end
456
+
457
+ private
458
+
459
+ def raise_on_missing_translations_in(environment)
460
+ config = 'config.action_view.raise_on_missing_translations = true'
461
+
462
+ uncomment_lines("config/environments/#{environment}.rb", config)
463
+ end
464
+
465
+ def serve_static_files_line
466
+ "config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?\n"
467
+ end
468
+ end