Class: Kazan::AppBuilder

Inherits:
Rails::AppBuilder
  • Object
show all
Includes:
Actions
Defined in:
lib/kazan/app_builder.rb

Instance Method Summary collapse

Methods included from Actions

#configure_action_mailer_host, #configure_application_file, #configure_environment, #replace_in_file

Instance Method Details

#assets_configObject



67
68
69
70
71
# File 'lib/kazan/app_builder.rb', line 67

def assets_config
  copy_file 'browserslist', 'app/assets/stylesheets/browserslist'
  copy_file 'errors.rb', 'config/initializers/errors.rb'
  copy_file 'json_encoding.rb', 'config/initializers/json_encoding.rb'
end

#bittersObject



178
179
180
# File 'lib/kazan/app_builder.rb', line 178

def bitters
  run 'bitters install --path app/assets/stylesheets'
end

#bullet_configObject



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

def bullet_config
  template 'bullet.rb', 'config/initializers/bullet.rb'
end

#bundler_audit_configObject



195
196
197
198
# File 'lib/kazan/app_builder.rb', line 195

def bundler_audit_config
  copy_file 'bundler_audit.rake', 'lib/tasks/bundler_audit.rake'
  append_file 'Rakefile', %{\ntask default: 'bundler:audit'\n}
end

#database_tablesObject



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

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

#dotenvsObject



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

def dotenvs
  directory 'envs', '.'
end

#empty_directoriesObject



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/kazan/app_builder.rb', line 279

def empty_directories
  [
    'app/assets/fonts',
    'app/controllers/api',
    'app/controllers/web',
    'app/services',
    'app/policies',
    'app/validations',
    'app/views/shared',
    'spec/controllers',
    'spec/factories',
    'spec/helpers',
    'spec/models',
    'spec/mailers',
    'spec/requests',
    'spec/routing',
  ].each do |dir|
    empty_directory_with_keep_file dir
  end
end

#exception_on_delivery_errorsObject



81
82
83
84
# File 'lib/kazan/app_builder.rb', line 81

def exception_on_delivery_errors
 replace_in_file 'config/environments/development.rb',
   'raise_delivery_errors = false', 'raise_delivery_errors = true'
end

#exception_on_missing_assets_in_testObject



200
201
202
# File 'lib/kazan/app_builder.rb', line 200

def exception_on_missing_assets_in_test
  configure_environment 'test', 'config.assets.raise_runtime_errors = true'
end

#exception_on_missing_translationsObject



95
96
97
98
# File 'lib/kazan/app_builder.rb', line 95

def exception_on_missing_translations
  exception_on_missing_translations_in 'development'
  exception_on_missing_translations_in 'test'
end

#exception_on_unpermitted_parametersObject



86
87
88
89
90
91
92
93
# File 'lib/kazan/app_builder.rb', line 86

def exception_on_unpermitted_parameters
  config = "config.action_controller.action_on_unpermitted_parameters = :raise\n\n  RUBY\n\n  inject_into_class 'config/application.rb', 'Application', config\nend\n"

#foreman_configObject



123
124
125
# File 'lib/kazan/app_builder.rb', line 123

def foreman_config
  template 'Procfile.erb', 'Procfile'
end

#gemfileObject



13
14
15
# File 'lib/kazan/app_builder.rb', line 13

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

#gemfile_apiObject



17
18
19
# File 'lib/kazan/app_builder.rb', line 17

def gemfile_api
  template 'Gemfile.api.erb', 'Gemfile', force: true
end

#gitignoreObject



9
10
11
# File 'lib/kazan/app_builder.rb', line 9

def gitignore
  copy_file 'project_gitignore', '.gitignore', force: true
end

#init_commitObject



300
301
302
303
304
# File 'lib/kazan/app_builder.rb', line 300

def init_commit
  run 'git init'
  run 'git add .'
  run 'git commit -m "Init commit"'
end

#letter_opener_configObject



100
101
102
103
104
105
106
107
108
# File 'lib/kazan/app_builder.rb', line 100

def letter_opener_config
  letter_opener_settings = "  # Letter opener settings\n  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }\n  config.action_mailer.delivery_method = :letter_opener\n  RUBY\n\n  configure_environment 'development', letter_opener_settings\nend\n"

#postgres_configObject



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

def postgres_config
  template 'database.yml.erb', 'config/database.yml', force: true
  template 'database.yml.erb', 'config/database.yml.example'
end

#puma_configObject



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

def puma_config
  copy_file 'puma.rb', 'config/puma.rb', force: true
end

#quiet_assets_configObject



114
115
116
117
118
119
120
121
# File 'lib/kazan/app_builder.rb', line 114

def quiet_assets_config
  config = "config.assets.quiet = true\n\n  RUBY\n\n  inject_into_class 'config/application.rb', 'Application', config\nend\n"

#rack_canonical_host_configObject



258
259
260
261
262
263
264
265
# File 'lib/kazan/app_builder.rb', line 258

def rack_canonical_host_config
  config = "  config.middleware.use Rack::CanonicalHost, ENV.fetch(\"APPLICATION_HOST\")\n  RUBY\n\n  inject_into_file \"config/environments/production.rb\", config,\n    after: \"Rails.application.configure do\"\nend\n"

#rack_deflater_configObject



267
268
269
# File 'lib/kazan/app_builder.rb', line 267

def rack_deflater_config
  configure_environment "production", "config.middleware.use Rack::Deflater"
end

#rack_mini_profiler_configObject



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

def rack_mini_profiler_config
  copy_file 'rack_mini_profiler.rb', 'config/initializers/rack_mini_profiler.rb'
end

#rack_timeout_configObject



249
250
251
252
253
254
255
256
# File 'lib/kazan/app_builder.rb', line 249

def rack_timeout_config
  rack_timeout_config = "  Rack::Timeout.timeout = (ENV[\"RACK_TIMEOUT\"] || 10).to_i\n\n  RUBY\n\n  append_file 'config/environments/production.rb', rack_timeout_config\nend\n"

#rails_generators_configObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/kazan/app_builder.rb', line 127

def rails_generators_config
  config = "config.generators do |generate|\n  generate.helper false\n  generate.javascript_engine 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"

#readmeObject



5
6
7
# File 'lib/kazan/app_builder.rb', line 5

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

#refillsObject



173
174
175
176
# File 'lib/kazan/app_builder.rb', line 173

def refills
  generate 'refills:import', 'flashes'
  remove_dir 'app/views/refills'
end


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

def remove_turbolinks
  replace_in_file(
    "app/assets/javascripts/application.js",
    "//= require turbolinks",
    "")
end

#rollbar_configObject



271
272
273
# File 'lib/kazan/app_builder.rb', line 271

def rollbar_config
  copy_file 'rollbar.rb', 'config/initializers/rollbar.rb'
end

#rspec_configObject



224
225
226
# File 'lib/kazan/app_builder.rb', line 224

def rspec_config
  generate 'rspec:install'
end

#rspec_replace_configObject



228
229
230
231
# File 'lib/kazan/app_builder.rb', line 228

def rspec_replace_config
  copy_file 'rails_helper.rb', 'spec/rails_helper.rb', force: true
  copy_file 'spec_helper.rb', 'spec/spec_helper.rb', force: true
end

#ruby_versionObject



21
22
23
# File 'lib/kazan/app_builder.rb', line 21

def ruby_version
  create_file '.ruby-version', "#{Kazan::RUBY_PROJECT_VERSION}\n"
end

#settingsObject



77
78
79
# File 'lib/kazan/app_builder.rb', line 77

def settings
  template 'settings.yml.erb', 'config/settings.yml'
end

#shared_flashObject



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

def shared_flash
  copy_file '_flashes.html.erb', 'app/views/layouts/shared/_flashes.html.erb'
  copy_file 'flashes_helper.rb', 'app/helpers/flashes_helper.rb'
end

#shared_javascriptObject



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

def shared_javascript
  copy_file '_javascript.html.erb', 'app/views/layouts/shared/_javascript.html.erb'
end

#shared_layoutObject



63
64
65
# File 'lib/kazan/app_builder.rb', line 63

def shared_layout
  copy_file 'application.html.erb', 'app/views/layouts/application.html.erb', force: true
end

#shared_stylesObject



59
60
61
# File 'lib/kazan/app_builder.rb', line 59

def shared_styles
  copy_file '_styles.html.erb', 'app/views/layouts/shared/_styles.html.erb'
end

#shared_views_directoryObject



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

def shared_views_directory
  empty_directory 'app/views/layouts/shared'
end

#simple_form_configObject



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

def simple_form_config
  bundle_command 'exec rails generate simple_form:install'
end

#smtp_configObject



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/kazan/app_builder.rb', line 233

def smtp_config
  copy_file 'smtp.rb', 'config/smtp.rb'

  prepend_file 'config/environments/production.rb',
    %{require Rails.root.join("config/smtp")\n}

  config = "  config.action_mailer.delivery_method = :smtp\n  config.action_mailer.smtp_settings = SMTP_SETTINGS\n\n  RUBY\n\n  inject_into_file 'config/environments/production.rb', config,\n    after: \"config.action_mailer.raise_delivery_errors = false\"\nend\n"

#spec_action_mailer_configObject



208
209
210
# File 'lib/kazan/app_builder.rb', line 208

def spec_action_mailer_config
  copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb'
end

#spec_database_cleaner_configObject



212
213
214
# File 'lib/kazan/app_builder.rb', line 212

def spec_database_cleaner_config
  copy_file 'database_cleaner.rb', 'spec/support/database_cleaner.rb'
end

#spec_factory_girl_configObject



220
221
222
# File 'lib/kazan/app_builder.rb', line 220

def spec_factory_girl_config
  copy_file 'factory_girl.rb', 'spec/support/factory_girl.rb'
end

#spec_shoulda_matchers_configObject



216
217
218
# File 'lib/kazan/app_builder.rb', line 216

def spec_shoulda_matchers_config
  copy_file 'shoulda_matchers.rb', 'spec/support/shoulda_matchers.rb'
end

#spec_translations_configObject



204
205
206
# File 'lib/kazan/app_builder.rb', line 204

def spec_translations_config
  copy_file 'i18n.rb', 'spec/support/i18n.rb'
end

#springObject



275
276
277
# File 'lib/kazan/app_builder.rb', line 275

def spring
  bundle_command 'exec spring binstub --all'
end

#static_pagesObject



182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/kazan/app_builder.rb', line 182

def static_pages
  meta_tags = "<meta charset=\"utf-8\" />\n<meta name=\"ROBOTS\" content=\"NOODP\" />\n<meta name=\"viewport\" content=\"initial-scale=1\" />\n  EOS\n\n  %w(500 404 422).each do |page|\n    inject_into_file \"public/\#{page}.html\", meta_tags, after: \"<head>\\n\"\n    replace_in_file \"public/\#{page}.html\", /<!--.+-->\\n/, ''\n  end\nend\n"

#stylesheets_gemsObject



151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/kazan/app_builder.rb', line 151

def stylesheets_gems
  gems = "\ngem 'bourbon', '5.0.0.beta.6'\ngem 'neat', '~> 1.8.0'\ngem 'refills', group: [:development, :test]\n  RUBY\n\n  inject_into_file 'Gemfile', gems,\n    after: \"gem 'sass-rails', '~> 5.0'\\n\"\n\n  Bundler.with_clean_env { run 'bundle install' }\nend\n"

#stylesheets_manifestObject



165
166
167
168
169
170
171
# File 'lib/kazan/app_builder.rb', line 165

def stylesheets_manifest
  remove_file 'app/assets/stylesheets/application.css'
  copy_file(
    'application.scss',
    'app/assets/stylesheets/application.scss',
    force: true)
end