Class: Code42Template::AppBuilder

Inherits:
Rails::AppBuilder
  • Object
show all
Extended by:
Forwardable
Includes:
Actions
Defined in:
lib/code42template/app_builder.rb

Instance Method Summary collapse

Methods included from Actions

#configure_application_file, #configure_environment, #replace_in_file

Instance Method Details

#add_bullet_gem_configurationObject



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/code42template/app_builder.rb', line 223

def add_bullet_gem_configuration
  config = <<RUBY
  config.after_initialize do
Bullet.enable = true
Bullet.bullet_logger = true
Bullet.rails_logger = true
  end
RUBY

  inject_into_file(
    "config/environments/development.rb",
    config,
    after: "config.file_watcher = ActiveSupport::EventedFileUpdateChecker\n",
  )
end

#add_puma_configurationObject



51
52
53
# File 'lib/code42template/app_builder.rb', line 51

def add_puma_configuration
  copy_file "puma.rb", "config/puma.rb", force: true
end

#configure_feature_testsObject



213
214
215
216
217
218
219
220
221
# File 'lib/code42template/app_builder.rb', line 213

def configure_feature_tests
  inject_into_file(
    'config/environments/test.rb',
    "  config.webpack.dev_server.enabled = false\n",
    after: "Rails.application.configure do\n",
  )

  template 'feature_helper.rb.erb', 'spec/feature_helper.rb'
end

#configure_quiet_assetsObject



143
144
145
146
147
148
149
# File 'lib/code42template/app_builder.rb', line 143

def configure_quiet_assets
  config = <<-RUBY
config.assets.quiet = true
  RUBY

  inject_into_class "config/application.rb", "Application", config
end

#configure_time_formatsObject



73
74
75
76
# File 'lib/code42template/app_builder.rb', line 73

def configure_time_formats
  remove_file "config/locales/en.yml"
  template "config_locales_pt-BR.yml.erb", "config/locales/pt-BR.yml"
end

#copy_dotfilesObject



97
98
99
100
# File 'lib/code42template/app_builder.rb', line 97

def copy_dotfiles
  directory("dotfiles", ".")
  copy_file 'test_env_eslintrc', 'spec/javascripts/.eslintrc'
end

#copy_js_root_filesObject



166
167
168
169
170
# File 'lib/code42template/app_builder.rb', line 166

def copy_js_root_files
  %w(package.json Procfile mocha-webpack.opts).each do |root_file|
    copy_file root_file, root_file
  end
end

#copy_js_spec_filesObject



172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/code42template/app_builder.rb', line 172

def copy_js_spec_files
  %w(
    index.browser.js
    index.integration.js
    unit/smoke.spec.js
    integration/smoke.spec.js
  ).each do |js_spec_file|
    copy_file(
      "spec/javascripts/#{js_spec_file}",
      "spec/javascripts/#{js_spec_file}"
    )
  end
end

#copy_rspec_configObject



46
47
48
49
# File 'lib/code42template/app_builder.rb', line 46

def copy_rspec_config
  copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
  copy_file 'rails_helper.rb', 'spec/rails_helper.rb'
end

#copy_webpack_and_karma_configObject



186
187
188
189
190
191
192
193
194
195
# File 'lib/code42template/app_builder.rb', line 186

def copy_webpack_and_karma_config
  %w(
    karma.conf.js
    webpack.config.js
    webpack.config.test.js
    webpack.config.test.browser.js
  ).each do |config_file|
    copy_file config_file, "config/#{config_file}"
  end
end

#copy_webpack_entry_fileObject



197
198
199
200
201
202
203
# File 'lib/code42template/app_builder.rb', line 197

def copy_webpack_entry_file
  copy_file(
    "application.js",
    "app/assets/javascripts/application.js",
    force: true
  )
end

#create_databaseObject



60
61
62
# File 'lib/code42template/app_builder.rb', line 60

def create_database
  bundle_command 'exec rake db:create db:migrate'
end

#create_setup_scriptObject



110
111
112
# File 'lib/code42template/app_builder.rb', line 110

def create_setup_script
  copy_file 'setup', 'bin/setup', force: true
end

#customize_error_pagesObject



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/code42template/app_builder.rb', line 114

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

#gemfileObject



33
34
35
# File 'lib/code42template/app_builder.rb', line 33

def gemfile
  template "Gemfile.erb", "Gemfile"
end

#gitignoreObject



29
30
31
# File 'lib/code42template/app_builder.rb', line 29

def gitignore
  copy_file "code42_gitignore", ".gitignore"
end

#heroku_adapterObject



248
249
250
# File 'lib/code42template/app_builder.rb', line 248

def heroku_adapter
  @heroku_adapter ||= Adapters::Heroku.new(self)
end

#init_gitObject



106
107
108
# File 'lib/code42template/app_builder.rb', line 106

def init_git
  run 'git init'
end

#inject_webpack_into_application_layoutObject



205
206
207
208
209
210
211
# File 'lib/code42template/app_builder.rb', line 205

def inject_webpack_into_application_layout
  replace_in_file(
    'app/views/layouts/application.html.erb',
    /javascript_include_tag 'application'/,
    "javascript_include_tag(*webpack_asset_paths('application'))"
  )
end

#provide_setup_scriptObject



37
38
39
40
# File 'lib/code42template/app_builder.rb', line 37

def provide_setup_script
  template "bin_setup", "bin/setup", force: true
  run "chmod a+x bin/setup"
end

#readmeObject



25
26
27
# File 'lib/code42template/app_builder.rb', line 25

def readme
  template 'README.md.erb', 'README.md'
end

#remove_uglifier_js_compressor_configObject



127
128
129
130
131
132
133
# File 'lib/code42template/app_builder.rb', line 127

def remove_uglifier_js_compressor_config
  gsub_file(
    'config/environments/production.rb',
    /^.+config.assets.js_compressor = :uglifier.*\n/,
    ''
  )
end

#set_ruby_to_version_being_usedObject



69
70
71
# File 'lib/code42template/app_builder.rb', line 69

def set_ruby_to_version_being_used
  create_file '.ruby-version', "#{Code42Template::RUBY_VERSION}\n"
end

#setup_background_jobsObject



64
65
66
67
# File 'lib/code42template/app_builder.rb', line 64

def setup_background_jobs
  copy_file 'active_job.rb', 'config/initializers/active_job.rb'
  copy_file 'sidekiq.yml', 'config/sidekiq.yml'
end

#setup_continuous_integrationObject



102
103
104
# File 'lib/code42template/app_builder.rb', line 102

def setup_continuous_integration
  template "travis.yml.erb", '.travis.yml'
end

#setup_default_directoriesObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/code42template/app_builder.rb', line 78

def setup_default_directories
  [
    'app/views/pages',
    'spec/lib',
    'spec/controllers',
    'spec/models',
    'spec/helpers',
    'spec/features',
    'spec/support/matchers',
    'spec/support/mixins',
    'spec/support/shared_examples',
    'spec/factories',
    'spec/javascripts/unit',
    'spec/javascripts/integration',
  ].each do |dir|
    empty_directory_with_keep_file dir
  end
end

#setup_health_taskObject



239
240
241
242
# File 'lib/code42template/app_builder.rb', line 239

def setup_health_task
  copy_file "health.rake", "lib/tasks/health.rake"
  append_file "Rakefile", %{\ntask default: "health"\n}
end

#setup_javascriptObject



155
156
157
158
159
160
161
162
163
164
# File 'lib/code42template/app_builder.rb', line 155

def setup_javascript
  copy_js_root_files
  copy_js_spec_files

  copy_webpack_and_karma_config
  copy_webpack_entry_file
  inject_webpack_into_application_layout

  run "npm install"
end

#setup_secret_tokenObject



42
43
44
# File 'lib/code42template/app_builder.rb', line 42

def setup_secret_token
  template 'secrets.yml', 'config/secrets.yml', force: true
end

#setup_springObject



151
152
153
# File 'lib/code42template/app_builder.rb', line 151

def setup_spring
  bundle_command "exec spring binstub --all"
end

#setup_test_env_action_dispatch_exceptionsObject



135
136
137
138
139
140
141
# File 'lib/code42template/app_builder.rb', line 135

def setup_test_env_action_dispatch_exceptions
  gsub_file(
    'config/environments/test.rb',
    'config.action_dispatch.show_exceptions = false',
    'config.action_dispatch.show_exceptions = true'
  )
end

#setup_webpack_tasksObject



244
245
246
# File 'lib/code42template/app_builder.rb', line 244

def setup_webpack_tasks
  copy_file "webpack.rake", "lib/tasks/webpack.rake"
end

#use_postgres_config_templateObject



55
56
57
58
# File 'lib/code42template/app_builder.rb', line 55

def use_postgres_config_template
  template 'postgresql_database.yml.erb', 'config/database.yml',
    force: true
end