Class: Suspenders::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Suspenders::AppBuilder
- Extended by:
- Forwardable
- Includes:
- Actions
- Defined in:
- lib/voyage/app_builder.rb,
lib/suspenders/app_builder.rb
Instance Method Summary collapse
- #accept_defaults ⇒ Object
- #add_bullet_gem_configuration ⇒ Object
- #add_canard_roles_to_devise_resource ⇒ Object
- #add_high_voltage_static_pages ⇒ Object
- #add_refills_to_layout ⇒ Object
- #add_refills_to_stylesheets ⇒ Object
- #add_sign_in_and_sign_out_routes_for_devise ⇒ Object
- #add_views_for_devise_resource(adding_first_and_last_name) ⇒ Object
- #agree?(prompt) ⇒ Boolean
- #authorize_devise_resource_for_index_action ⇒ Object
- #configure_action_mailer ⇒ Object
- #configure_action_mailer_in_specs ⇒ Object
- #configure_active_job ⇒ Object
- #configure_automatic_deployment ⇒ Object
- #configure_background_jobs_for_rspec ⇒ Object
- #configure_capybara_webkit ⇒ Object
- #configure_ci ⇒ Object
-
#configure_generators ⇒ Object
OVERRIDE SUSPENDERS METHODS #.
- #configure_i18n_for_missing_translations ⇒ Object
- #configure_i18n_for_test_environment ⇒ Object
- #configure_quiet_assets ⇒ Object
- #configure_rack_timeout ⇒ Object
- #configure_rspec ⇒ Object
- #configure_rvm_prepend_bin_to_path ⇒ Object
- #configure_simple_form ⇒ Object
- #configure_smtp ⇒ Object
- #configure_spec_support_features ⇒ Object
- #configure_time_formats ⇒ Object
- #convert_refill_views ⇒ Object
- #copy_dotfiles ⇒ Object
- #copy_miscellaneous_files ⇒ Object
- #create_application_layout ⇒ Object
- #create_database ⇒ Object
- #create_deploy_script ⇒ Object
- #create_github_repo(repo_name) ⇒ Object
- #create_heroku_apps(flags) ⇒ Object
- #create_partials_directory ⇒ Object
- #create_shared_css_overrides ⇒ Object
- #create_shared_flashes ⇒ Object
- #create_shared_javascripts ⇒ Object
- #customize_application_controller_for_devise(adding_first_and_last_name) ⇒ Object
- #customize_application_js ⇒ Object
- #customize_devise_views ⇒ Object
- #customize_error_pages ⇒ Object
- #customize_resource_controller_for_devise(adding_first_and_last_name) ⇒ Object
- #customize_user_factory(adding_first_and_last_name) ⇒ Object
- #disallow_wrapping_parameters ⇒ Object
- #downgrade_neat_1_8_so_refills_media_mixin_works ⇒ Object
- #enable_database_cleaner ⇒ Object
- #enable_rack_canonical_host ⇒ Object
- #enable_rack_deflater ⇒ Object
- #gemfile ⇒ Object
- #generate_data_migrations ⇒ Object
-
#generate_factories_file ⇒ Object
——————————– setup_test_environment overrides ——————————–.
-
#generate_refills ⇒ Object
————————- ADDING REFILLS COMPONENTS ————————-.
- #generate_rspec ⇒ Object
- #generate_ruby_version_and_gemset ⇒ Object
-
#generate_seeder_templates(using_devise:) ⇒ Object
—————- END DEVISE SETUP —————-.
-
#generate_test_environment ⇒ Object
—————————– END ADDING REFILLS COMPONENTS —————————–.
- #gitignore ⇒ Object
- #init_git ⇒ Object
-
#install_devise ⇒ Object
———— DEVISE SETUP ————.
- #provide_dev_prime_task ⇒ Object
- #provide_setup_script ⇒ Object
- #provide_shoulda_matchers_config ⇒ Object
- #raise_on_delivery_errors ⇒ Object
- #raise_on_missing_assets_in_test ⇒ Object
- #raise_on_unpermitted_parameters ⇒ Object
-
#rake_db_setup ⇒ Object
Do this last.
- #readme ⇒ Object
-
#remove_config_comment_lines ⇒ Object
———————————— End setup_test_environment overrides ————————————.
- #remove_routes_comment_lines ⇒ Object
- #remove_turbolinks ⇒ Object
- #replace_default_puma_configuration ⇒ Object
- #replace_gemfile(path) ⇒ Object
- #require_files_in_lib ⇒ Object
- #set_ruby_to_version_being_used ⇒ Object
- #set_test_delivery_method ⇒ Object
- #set_up_factory_girl_for_rspec ⇒ Object
- #set_up_forego ⇒ Object
- #set_up_hound ⇒ Object
- #setup_asset_host ⇒ Object
- #setup_bundler_audit ⇒ Object
- #setup_default_directories ⇒ Object
- #setup_default_rake_task ⇒ Object
- #setup_rack_mini_profiler ⇒ Object
- #setup_secret_token ⇒ Object
- #setup_segment ⇒ Object
- #setup_spring ⇒ Object
- #update_application_layout_for_slim ⇒ Object
- #update_devise_initializer ⇒ Object
- #update_gemset_in_gemfile ⇒ Object
- #update_test_environment ⇒ Object
- #use_postgres_config_template ⇒ Object
- #use_slim ⇒ Object
Methods included from Actions
#action_mailer_host, #configure_application_file, #configure_environment, #replace_in_file
Instance Method Details
#accept_defaults ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/voyage/app_builder.rb', line 10 def accept_defaults if agree?('Would you like to accept all defaults? [slim, devise w/ first & last name, refills nav & footer] (Y/n)') @@accept_defaults = true else @@accept_defaults = false end end |
#add_bullet_gem_configuration ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/suspenders/app_builder.rb', line 62 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.action_mailer.raise_delivery_errors = true\n", ) end |
#add_canard_roles_to_devise_resource ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/voyage/app_builder.rb', line 241 def add_canard_roles_to_devise_resource inject_into_file 'app/models/user.rb', before: /^end/ do <<-RUBY.gsub(/^ {6}/, '') \n # Permissions cascade/inherit through the roles listed below. The order of # this list is important, it should progress from least to most privelage ROLES = [:admin].freeze acts_as_user roles: ROLES roles ROLES RUBY end end |
#add_high_voltage_static_pages ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/voyage/app_builder.rb', line 325 def add_high_voltage_static_pages template '../templates/about.html.erb', "app/views/pages/about.html.#{@@use_slim ? 'slim' : 'erb'}" template '../templates/welcome.html.erb', "app/views/pages/welcome.html.erb" inject_into_file 'config/routes.rb', before: /^end/ do <<-RUBY.gsub(/^ {6}/, '') root 'high_voltage/pages#show', id: 'welcome' RUBY end create_file 'config/initializers/high_voltage.rb' do <<-RUBY.gsub(/^ {8}/, '') HighVoltage.configure do |config| config.route_drawer = HighVoltage::RouteDrawers::Root end RUBY end end |
#add_refills_to_layout ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/voyage/app_builder.rb', line 376 def add_refills_to_layout if @@use_slim inject_into_file 'app/views/layouts/application.html.slim', before: ' = yield' do <<-RUBY.gsub(/^ {8}/, '') = render 'refills/navigation' RUBY end inject_into_file 'app/views/layouts/application.html.slim', before: ' = render "javascript"' do <<-RUBY.gsub(/^ {8}/, '') = render 'refills/footer' RUBY end else inject_into_file 'app/views/layouts/application.html.erb', before: ' <%= yield %>' do <<-RUBY.gsub(/^ {8}/, '') <%= render 'refills/navigation' %> RUBY end inject_into_file 'app/views/layouts/application.html.erb', before: ' <%= render "javascript" %>' do <<-RUBY.gsub(/^ {8}/, '') <%= render 'refills/footer' %> RUBY end end end |
#add_refills_to_stylesheets ⇒ Object
398 399 400 401 402 403 404 |
# File 'lib/voyage/app_builder.rb', line 398 def add_refills_to_stylesheets inject_into_file 'app/assets/stylesheets/application.scss', after: '@import "refills/flashes";' do <<-RUBY.gsub(/^ {8}/, '') \n@import "refills/navigation"; @import "refills/footer"; RUBY end end |
#add_sign_in_and_sign_out_routes_for_devise ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/voyage/app_builder.rb', line 262 def add_sign_in_and_sign_out_routes_for_devise inject_into_file 'config/routes.rb', before: /^end/ do <<-RUBY.gsub(/^ {6}/, '') authenticated :user do # root to: 'dashboard#show', as: :authenticated_root end devise_scope :user do get 'sign-in', to: 'devise/sessions#new' get 'sign-out', to: 'devise/sessions#destroy' end RUBY end end |
#add_views_for_devise_resource(adding_first_and_last_name) ⇒ Object
215 216 217 218 |
# File 'lib/voyage/app_builder.rb', line 215 def add_views_for_devise_resource(adding_first_and_last_name) config = { adding_first_and_last_name: adding_first_and_last_name } template '../templates/users_index.html.slim.erb', 'app/views/users/index.html.slim', config end |
#agree?(prompt) ⇒ Boolean
3 4 5 6 7 8 |
# File 'lib/voyage/app_builder.rb', line 3 def agree?(prompt) puts prompt response = STDIN.gets.chomp response.empty? || %w(y yes).include?(response.downcase.strip) end |
#authorize_devise_resource_for_index_action ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/voyage/app_builder.rb', line 220 def generate "canard:ability user can:manage:user cannot:destroy:user" generate "canard:ability admin can:destroy:user" %w(admins users).each do |resource_name| replace_in_file "spec/abilities/#{resource_name}_spec.rb", 'Factory.create', 'build_stubbed' replace_in_file "spec/abilities/#{resource_name}_spec.rb", "require_relative '../spec_helper'", "require 'rails_helper'" replace_in_file "spec/abilities/#{resource_name}_spec.rb", 'require "cancan/matchers"', "require_relative '../support/matchers/custom_cancan'" # NOTE: (2016-02-09) jonk => this replaces both should and should_not and results in is_expected.to_not in the latter case replace_in_file "spec/abilities/#{resource_name}_spec.rb", 'should', "is_expected.to" end replace_in_file 'spec/abilities/users_spec.rb', ':user_user', ':user' replace_in_file 'spec/abilities/admins_spec.rb', ':admin_user', ':user, :admin' replace_in_file 'spec/abilities/admins_spec.rb', '@user = build_stubbed(:user, :admin)', '@admin = build_stubbed(:user, :admin)' replace_in_file 'spec/abilities/admins_spec.rb', 'subject { Ability.new(@user) }', 'subject { Ability.new(@admin) }' generate "migration add_roles_mask_to_users roles_mask:integer" template '../templates/custom_cancan_matchers.rb', 'spec/support/matchers/custom_cancan.rb' end |
#configure_action_mailer ⇒ Object
311 312 313 314 315 |
# File 'lib/suspenders/app_builder.rb', line 311 def configure_action_mailer action_mailer_host "development", %{"localhost:3000"} action_mailer_host "test", %{"www.example.com"} action_mailer_host "production", %{ENV.fetch("APPLICATION_HOST")} end |
#configure_action_mailer_in_specs ⇒ Object
286 287 288 |
# File 'lib/suspenders/app_builder.rb', line 286 def configure_action_mailer_in_specs copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb' end |
#configure_active_job ⇒ Object
317 318 319 320 321 322 |
# File 'lib/suspenders/app_builder.rb', line 317 def configure_active_job configure_application_file( "config.active_job.queue_adapter = :delayed_job" ) configure_environment "test", "config.active_job.queue_adapter = :inline" end |
#configure_automatic_deployment ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/suspenders/app_builder.rb', line 381 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 |
#configure_background_jobs_for_rspec ⇒ Object
486 487 488 |
# File 'lib/voyage/app_builder.rb', line 486 def configure_background_jobs_for_rspec run 'rails g delayed_job:active_record' end |
#configure_capybara_webkit ⇒ Object
490 491 492 |
# File 'lib/voyage/app_builder.rb', line 490 def # NOTE: (2016-02-03) jonk => don't want this end |
#configure_ci ⇒ Object
482 483 484 |
# File 'lib/voyage/app_builder.rb', line 482 def configure_ci template "circle.yml.erb", "circle.yml" end |
#configure_generators ⇒ Object
OVERRIDE SUSPENDERS METHODS #
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/voyage/app_builder.rb', line 453 def configure_generators config = <<-RUBY.gsub(/^ {4}/, '') config.generators do |g| g.helper false g.javascript_engine false g.request_specs false g.routing_specs false g.stylesheets false g.test_framework :rspec g.view_specs false g.fixture_replacement :factory_girl, dir: 'spec/factories' g.template_engine :slim end RUBY inject_into_class 'config/application.rb', 'Application', config end |
#configure_i18n_for_missing_translations ⇒ Object
277 278 279 280 |
# File 'lib/suspenders/app_builder.rb', line 277 def configure_i18n_for_missing_translations raise_on_missing_translations_in("development") raise_on_missing_translations_in("test") end |
#configure_i18n_for_test_environment ⇒ Object
273 274 275 |
# File 'lib/suspenders/app_builder.rb', line 273 def configure_i18n_for_test_environment copy_file "i18n.rb", "spec/support/i18n.rb" end |
#configure_quiet_assets ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/suspenders/app_builder.rb', line 87 def configure_quiet_assets config = <<-RUBY config.assets.quiet = true RUBY inject_into_class "config/application.rb", "Application", config end |
#configure_rack_timeout ⇒ Object
299 300 301 302 303 304 305 |
# File 'lib/suspenders/app_builder.rb', line 299 def configure_rack_timeout rack_timeout_config = <<-RUBY Rack::Timeout.timeout = (ENV["RACK_TIMEOUT"] || 10).to_i RUBY append_file "config/environments/production.rb", rack_timeout_config end |
#configure_rspec ⇒ Object
262 263 264 265 266 267 |
# File 'lib/suspenders/app_builder.rb', line 262 def configure_rspec remove_file "spec/rails_helper.rb" remove_file "spec/spec_helper.rb" copy_file "rails_helper.rb", "spec/rails_helper.rb" copy_file "spec_helper.rb", "spec/spec_helper.rb" end |
#configure_rvm_prepend_bin_to_path ⇒ Object
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/voyage/app_builder.rb', line 433 def configure_rvm_prepend_bin_to_path run "rm -f $rvm_path/hooks/after_cd_bundler" run "touch $rvm_path/hooks/after_cd_bundler" git_safe_dir = <<-RUBY.gsub(/^ {8}/, '') #!/usr/bin/env bash export PATH=".git/safe/../../bin:$PATH" RUBY run "echo '#{git_safe_dir}' >> $rvm_path/hooks/after_cd_bundler" run 'chmod +x $rvm_path/hooks/after_cd_bundler' run 'mkdir -p .git/safe' end |
#configure_simple_form ⇒ Object
307 308 309 |
# File 'lib/suspenders/app_builder.rb', line 307 def configure_simple_form bundle_command "exec rails generate simple_form:install" end |
#configure_smtp ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/suspenders/app_builder.rb', line 134 def configure_smtp copy_file 'smtp.rb', 'config/smtp.rb' prepend_file 'config/environments/production.rb', %{require Rails.root.join("config/smtp")\n} config = <<-RUBY config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = SMTP_SETTINGS RUBY inject_into_file 'config/environments/production.rb', config, after: "config.action_mailer.raise_delivery_errors = false" end |
#configure_spec_support_features ⇒ Object
257 258 259 260 |
# File 'lib/suspenders/app_builder.rb', line 257 def configure_spec_support_features empty_directory_with_keep_file 'spec/features' empty_directory_with_keep_file 'spec/support/features' end |
#configure_time_formats ⇒ Object
294 295 296 297 |
# File 'lib/suspenders/app_builder.rb', line 294 def configure_time_formats remove_file "config/locales/en.yml" template "config_locales_en.yml.erb", "config/locales/en.yml" end |
#convert_refill_views ⇒ Object
369 370 371 372 373 374 |
# File 'lib/voyage/app_builder.rb', line 369 def convert_refill_views inside('lib') do # arbitrary, run in context of newly generated app run "erb2slim '../app/views/refills' '../app/views/refills'" run "erb2slim -d '../app/views/refills'" end end |
#copy_dotfiles ⇒ Object
350 351 352 |
# File 'lib/suspenders/app_builder.rb', line 350 def copy_dotfiles directory("dotfiles", ".") end |
#copy_miscellaneous_files ⇒ Object
411 412 413 414 415 |
# File 'lib/suspenders/app_builder.rb', line 411 def copy_miscellaneous_files copy_file "browserslist", "browserslist" copy_file "errors.rb", "config/initializers/errors.rb" copy_file "json_encoding.rb", "config/initializers/json_encoding.rb" end |
#create_application_layout ⇒ Object
217 218 219 220 221 |
# File 'lib/suspenders/app_builder.rb', line 217 def create_application_layout template 'suspenders_layout.html.erb.erb', 'app/views/layouts/application.html.erb', force: true end |
#create_database ⇒ Object
228 229 230 |
# File 'lib/suspenders/app_builder.rb', line 228 def create_database bundle_command 'exec rake db:create db:migrate' end |
#create_deploy_script ⇒ Object
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/suspenders/app_builder.rb', line 363 def create_deploy_script copy_file "bin_deploy", "bin/deploy" instructions = <<-MARKDOWN ## Deploying If you have previously run the `./bin/setup` script, you can deploy to staging and production with: $ ./bin/deploy staging $ ./bin/deploy production MARKDOWN append_file "README.md", instructions run "chmod a+x bin/deploy" end |
#create_github_repo(repo_name) ⇒ Object
393 394 395 |
# File 'lib/suspenders/app_builder.rb', line 393 def create_github_repo(repo_name) run "hub create #{repo_name}" end |
#create_heroku_apps(flags) ⇒ Object
358 359 360 361 |
# File 'lib/suspenders/app_builder.rb', line 358 def create_heroku_apps(flags) create_staging_heroku_app(flags) create_production_heroku_app(flags) end |
#create_partials_directory ⇒ Object
197 198 199 |
# File 'lib/suspenders/app_builder.rb', line 197 def create_partials_directory empty_directory 'app/views/application' end |
#create_shared_css_overrides ⇒ Object
210 211 212 213 214 215 |
# File 'lib/suspenders/app_builder.rb', line 210 def create_shared_css_overrides copy_file( "_css_overrides.html.erb", "app/views/application/_css_overrides.html.erb", ) end |
#create_shared_flashes ⇒ Object
201 202 203 204 |
# File 'lib/suspenders/app_builder.rb', line 201 def create_shared_flashes copy_file "_flashes.html.erb", "app/views/application/_flashes.html.erb" copy_file "flashes_helper.rb", "app/helpers/flashes_helper.rb" end |
#create_shared_javascripts ⇒ Object
206 207 208 |
# File 'lib/suspenders/app_builder.rb', line 206 def create_shared_javascripts copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb' end |
#customize_application_controller_for_devise(adding_first_and_last_name) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/voyage/app_builder.rb', line 154 def customize_application_controller_for_devise(adding_first_and_last_name) inject_into_file 'app/controllers/application_controller.rb', after: " protect_from_forgery with: :exception" do <<-RUBY.gsub(/^ {6}/, '').gsub(/^ {8}\n/, '') \n before_action :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.permit( :sign_up, keys: [ #{':first_name,' if adding_first_and_last_name} #{':last_name,' if adding_first_and_last_name} :email, :password, :password_confirmation, :remember_me, ] ) devise_parameter_sanitizer.permit( :sign_in, keys: [ :login, :email, :password, :remember_me ] ) devise_parameter_sanitizer.permit( :account_update, keys: [ #{':first_name,' if adding_first_and_last_name} #{':last_name,' if adding_first_and_last_name} :email, :password, :password_confirmation, :current_password, ] ) end RUBY end end |
#customize_application_js ⇒ Object
306 307 308 |
# File 'lib/voyage/app_builder.rb', line 306 def customize_application_js template '../templates/application.js', 'app/assets/javascripts/application.js', force: true end |
#customize_devise_views ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/voyage/app_builder.rb', line 134 def customize_devise_views %w(edit new).each do |file| if @@use_slim file_path = "app/views/devise/registrations/#{file}.html.slim" inject_into_file file_path, before: " = f.input :email, required: true, autofocus: true" do <<-'RUBY'.gsub(/^ {8}/, '') = f.input :first_name, required: true, autofocus: true = f.input :last_name, required: true RUBY end else file_path = "app/views/devise/registrations/#{file}.html.erb" inject_into_file file_path, before: " <%= f.input :email, required: true, autofocus: true %>" do <<-'RUBY'.gsub(/^ {8}/, '') <%= f.input :first_name, required: true, autofocus: true %> <%= f.input :last_name, required: true %> RUBY end end end end |
#customize_error_pages ⇒ Object
417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/suspenders/app_builder.rb', line 417 def customize_error_pages =<<-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", , after: "<head>\n" replace_in_file "public/#{page}.html", /<!--.+-->\n/, '' end end |
#customize_resource_controller_for_devise(adding_first_and_last_name) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/voyage/app_builder.rb', line 197 def customize_resource_controller_for_devise(adding_first_and_last_name) bundle_command "exec rails generate controller users" inject_into_class "app/controllers/users_controller.rb", "UsersController" do <<-RUBY.gsub(/^ {6}/, '') # https://github.com/CanCanCommunity/cancancan/wiki/authorizing-controller-actions load_and_authorize_resource only: [:index, :show] RUBY end unless adding_first_and_last_name inject_into_file 'config/routes.rb', after: ' devise_for :users' do <<-RUBY.gsub(/^ {8}/, '') \n resources :users RUBY end end end |
#customize_user_factory(adding_first_and_last_name) ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/voyage/app_builder.rb', line 276 def customize_user_factory(adding_first_and_last_name) inject_into_file 'spec/factories/users.rb', before: /^ end/ do <<-'RUBY'.gsub(/^ {4}/, '') password 'password' sequence(:email) { |n| "user_#{n}@example.com" } trait :admin do roles [:admin] email '[email protected]' end RUBY end if adding_first_and_last_name inject_into_file 'spec/factories/users.rb', after: /roles \[:admin\]\n/ do <<-'RUBY'.gsub(/^ {4}/, '') first_name 'Admin' last_name 'User' RUBY end end end |
#disallow_wrapping_parameters ⇒ Object
193 194 195 |
# File 'lib/suspenders/app_builder.rb', line 193 def disallow_wrapping_parameters remove_file "config/initializers/wrap_parameters.rb" end |
#downgrade_neat_1_8_so_refills_media_mixin_works ⇒ Object
TEMP FIX
https://github.com/thoughtbot/bourbon/issues/993
https://github.com/thoughtbot/refills/issues/400
347 348 349 |
# File 'lib/voyage/app_builder.rb', line 347 def downgrade_neat_1_8_so_refills_media_mixin_works replace_in_file 'Gemfile', "gem 'neat', '~> 2.0.0.beta.1'", "gem 'neat', '~> 1.8.0'" end |
#enable_database_cleaner ⇒ Object
246 247 248 |
# File 'lib/suspenders/app_builder.rb', line 246 def enable_database_cleaner copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb' end |
#enable_rack_canonical_host ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/suspenders/app_builder.rb', line 150 def enable_rack_canonical_host config = <<-RUBY if ENV.fetch("HEROKU_APP_NAME", "").include?("staging-pr-") ENV["APPLICATION_HOST"] = ENV["HEROKU_APP_NAME"] + ".herokuapp.com" end config.middleware.use Rack::CanonicalHost, ENV.fetch("APPLICATION_HOST") RUBY inject_into_file( "config/environments/production.rb", config, after: "Rails.application.configure do", ) end |
#enable_rack_deflater ⇒ Object
167 168 169 |
# File 'lib/suspenders/app_builder.rb', line 167 def enable_rack_deflater configure_environment "production", "config.middleware.use Rack::Deflater" end |
#gemfile ⇒ Object
26 27 28 |
# File 'lib/suspenders/app_builder.rb', line 26 def gemfile template "Gemfile.erb", "Gemfile" end |
#generate_data_migrations ⇒ Object
319 320 321 322 323 |
# File 'lib/voyage/app_builder.rb', line 319 def generate_data_migrations generate 'data_migrations:install' empty_directory_with_keep_file 'db/data_migrate' end |
#generate_factories_file ⇒ Object
setup_test_environment overrides
478 479 480 |
# File 'lib/voyage/app_builder.rb', line 478 def generate_factories_file # NOTE: (2016-02-03) jonk => don't want this, we use individual factories end |
#generate_refills ⇒ Object
ADDING REFILLS COMPONENTS
358 359 360 361 362 363 364 365 366 367 |
# File 'lib/voyage/app_builder.rb', line 358 def generate_refills if @@accept_defaults || agree?('Would you like to install default Refill components? (Y/n)') bundle_command 'exec rails generate refills:import navigation' bundle_command 'exec rails generate refills:import footer' convert_refill_views if @@use_slim add_refills_to_layout add_refills_to_stylesheets end end |
#generate_rspec ⇒ Object
324 325 326 |
# File 'lib/suspenders/app_builder.rb', line 324 def generate_rspec generate 'rspec:install' end |
#generate_ruby_version_and_gemset ⇒ Object
315 316 317 |
# File 'lib/voyage/app_builder.rb', line 315 def generate_ruby_version_and_gemset create_file '.ruby-gemset', "#{app_name}\n" end |
#generate_seeder_templates(using_devise:) ⇒ Object
END DEVISE SETUP
300 301 302 303 304 |
# File 'lib/voyage/app_builder.rb', line 300 def generate_seeder_templates(using_devise:) config = { force: true, using_devise: using_devise } template '../templates/seeder.rb.erb', 'lib/seeder.rb', config template '../templates/seeds.rb.erb', 'db/seeds.rb', config end |
#generate_test_environment ⇒ Object
END ADDING REFILLS COMPONENTS
409 410 411 412 |
# File 'lib/voyage/app_builder.rb', line 409 def generate_test_environment template '../templates/controller_helpers.rb', 'spec/support/controller_helpers.rb' template '../templates/simplecov.rb', '.simplecov' end |
#gitignore ⇒ Object
22 23 24 |
# File 'lib/suspenders/app_builder.rb', line 22 def gitignore copy_file "suspenders_gitignore", ".gitignore" end |
#init_git ⇒ Object
354 355 356 |
# File 'lib/suspenders/app_builder.rb', line 354 def init_git run 'git init' end |
#install_devise ⇒ Object
DEVISE SETUP
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/voyage/app_builder.rb', line 94 def install_devise if @@accept_defaults || agree?('Would you like to install Devise? (Y/n)') bundle_command 'exec rails generate devise:install' if @@accept_defaults || agree?("Would you like to add first_name and last_name to the devise model? (Y/n)") adding_first_and_last_name = true bundle_command "exec rails generate resource user first_name:string last_name:string" replace_in_file 'spec/factories/users.rb', 'first_name "MyString"', 'first_name { Faker::Name.first_name }' replace_in_file 'spec/factories/users.rb', 'last_name "MyString"', 'last_name { Faker::Name.last_name }' end bundle_command "exec rails generate devise user" bundle_command 'exec rails generate devise:views' if @@use_slim inside('lib') do # arbitrary, run in context of newly generated app run "erb2slim '../app/views/devise' '../app/views/devise'" run "erb2slim -d '../app/views/devise'" end end customize_devise_views if adding_first_and_last_name customize_application_controller_for_devise(adding_first_and_last_name) customize_resource_controller_for_devise(adding_first_and_last_name) add_views_for_devise_resource(adding_first_and_last_name) add_canard_roles_to_devise_resource update_devise_initializer add_sign_in_and_sign_out_routes_for_devise customize_user_factory(adding_first_and_last_name) generate_seeder_templates(using_devise: true) else generate_seeder_templates(using_devise: false) end end |
#provide_dev_prime_task ⇒ Object
100 101 102 |
# File 'lib/suspenders/app_builder.rb', line 100 def provide_dev_prime_task copy_file 'dev.rake', 'lib/tasks/dev.rake' end |
#provide_setup_script ⇒ Object
95 96 97 98 |
# File 'lib/suspenders/app_builder.rb', line 95 def provide_setup_script template "bin_setup", "bin/setup", force: true run "chmod a+x bin/setup" end |
#provide_shoulda_matchers_config ⇒ Object
250 251 252 253 254 255 |
# File 'lib/suspenders/app_builder.rb', line 250 def provide_shoulda_matchers_config copy_file( "shoulda_matchers_config_rspec.rb", "spec/support/shoulda_matchers.rb" ) end |
#raise_on_delivery_errors ⇒ Object
41 42 43 44 |
# File 'lib/suspenders/app_builder.rb', line 41 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
37 38 39 |
# File 'lib/suspenders/app_builder.rb', line 37 def raise_on_missing_assets_in_test configure_environment "test", "config.assets.raise_runtime_errors = true" end |
#raise_on_unpermitted_parameters ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/suspenders/app_builder.rb', line 79 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 |
#rake_db_setup ⇒ Object
Do this last
428 429 430 431 |
# File 'lib/voyage/app_builder.rb', line 428 def rake_db_setup rake 'db:migrate' rake 'db:seed' if File.exist?('config/initializers/devise.rb') end |
#readme ⇒ Object
18 19 20 |
# File 'lib/suspenders/app_builder.rb', line 18 def readme template 'README.md.erb', 'README.md' end |
#remove_config_comment_lines ⇒ Object
End setup_test_environment overrides
497 498 499 |
# File 'lib/voyage/app_builder.rb', line 497 def remove_config_comment_lines # NOTE: (2016-02-09) jonk => don't want this end |
#remove_routes_comment_lines ⇒ Object
452 453 454 455 456 |
# File 'lib/suspenders/app_builder.rb', line 452 def remove_routes_comment_lines replace_in_file 'config/routes.rb', /Rails\.application\.routes\.draw do.*end/m, "Rails.application.routes.draw do\nend" end |
#remove_turbolinks ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/suspenders/app_builder.rb', line 46 def remove_turbolinks replace_in_file( "app/assets/javascripts/application.js", "//= require turbolinks", "" ) end |
#replace_default_puma_configuration ⇒ Object
328 329 330 |
# File 'lib/suspenders/app_builder.rb', line 328 def replace_default_puma_configuration copy_file "puma.rb", "config/puma.rb", force: true end |
#replace_gemfile(path) ⇒ Object
232 233 234 235 236 237 238 239 240 |
# File 'lib/suspenders/app_builder.rb', line 232 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 |
#require_files_in_lib ⇒ Object
310 311 312 313 |
# File 'lib/voyage/app_builder.rb', line 310 def require_files_in_lib create_file 'config/initializers/require_files_in_lib.rb', "Dir[File.join(Rails.root, 'lib', '**', '*.rb')].each { |l| require l }\n" end |
#set_ruby_to_version_being_used ⇒ Object
471 472 473 |
# File 'lib/voyage/app_builder.rb', line 471 def set_ruby_to_version_being_used create_file '.ruby-version', "#{Voyage::RUBY_VERSION}\n" end |
#set_test_delivery_method ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/suspenders/app_builder.rb', line 54 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_factory_girl_for_rspec ⇒ Object
122 123 124 |
# File 'lib/suspenders/app_builder.rb', line 122 def set_up_factory_girl_for_rspec copy_file 'factory_girl_rspec.rb', 'spec/support/factory_girl.rb' end |
#set_up_forego ⇒ Object
332 333 334 |
# File 'lib/suspenders/app_builder.rb', line 332 def set_up_forego copy_file "Procfile", "Procfile" end |
#set_up_hound ⇒ Object
130 131 132 |
# File 'lib/suspenders/app_builder.rb', line 130 def set_up_hound copy_file "hound.yml", ".hound.yml" end |
#setup_asset_host ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/suspenders/app_builder.rb', line 171 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"))' replace_in_file 'config/initializers/assets.rb', "config.assets.version = '1.0'", 'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")' config = <<-EOD config.public_file_server.headers = { "Cache-Control" => "public, max-age=31557600", } EOD configure_environment("production", config) end |
#setup_bundler_audit ⇒ Object
402 403 404 405 |
# File 'lib/suspenders/app_builder.rb', line 402 def setup_bundler_audit copy_file "bundler_audit.rake", "lib/tasks/bundler_audit.rake" append_file "Rakefile", %{\ntask default: "bundler:audit"\n} end |
#setup_default_directories ⇒ Object
336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/suspenders/app_builder.rb', line 336 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
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'lib/suspenders/app_builder.rb', line 458 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
30 31 32 33 34 35 |
# File 'lib/suspenders/app_builder.rb', line 30 def setup_rack_mini_profiler copy_file( "rack_mini_profiler.rb", "config/initializers/rack_mini_profiler.rb", ) end |
#setup_secret_token ⇒ Object
189 190 191 |
# File 'lib/suspenders/app_builder.rb', line 189 def setup_secret_token template 'secrets.yml', 'config/secrets.yml', force: true end |
#setup_segment ⇒ Object
397 398 399 400 |
# File 'lib/suspenders/app_builder.rb', line 397 def setup_segment copy_file '_analytics.html.erb', 'app/views/application/_analytics.html.erb' end |
#setup_spring ⇒ Object
407 408 409 |
# File 'lib/suspenders/app_builder.rb', line 407 def setup_spring bundle_command "exec spring binstub --all" end |
#update_application_layout_for_slim ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/voyage/app_builder.rb', line 32 def update_application_layout_for_slim find = <<-RUBY.gsub(/^ {6}/, '') <%# Configure default and controller-, and view-specific titles in config/locales/en.yml. For more see: https://github.com/calebthompson/title#usage %> RUBY replace = <<-RUBY.gsub(/^ {6}/, '') <% # Configure default and controller-, and view-specific titles in # config/locales/en.yml. For more see: # https://github.com/calebthompson/title#usage %> RUBY replace_in_file 'app/views/layouts/application.html.erb', find, replace inside('lib') do # arbitrary, run in context of newly generated app run "erb2slim '../app/views/layouts' '../app/views/layouts'" run "erb2slim -d '../app/views/layouts'" run "erb2slim '../app/views/application' '../app/views/application'" run "erb2slim -d '../app/views/application'" end # strip trailing space after closing "> in application layout before # trying to find and replace it replace_in_file 'app/views/layouts/application.html.slim', '| "> ', '| ">' find = <<-RUBY.gsub(/^ {6}/, '') | <body class=" = body_class | "> RUBY replace = <<-RUBY.gsub(/^ {6}/, '') body class="\#{body_class}" RUBY replace_in_file 'app/views/layouts/application.html.slim', find, replace find = <<-RUBY.gsub(/^ {6}/, '') = render "flashes" = yield = render "javascript" = render "css_overrides" RUBY # Bump renders in to be nested within body replace = <<-RUBY.gsub(/^ {6}/, '') = render "flashes" = yield = render "javascript" = render "css_overrides" RUBY replace_in_file 'app/views/layouts/application.html.slim', find, replace end |
#update_devise_initializer ⇒ Object
253 254 255 256 257 258 259 260 |
# File 'lib/voyage/app_builder.rb', line 253 def update_devise_initializer replace_in_file 'config/initializers/devise.rb', 'config.sign_out_via = :delete', 'config.sign_out_via = :get' replace_in_file 'config/initializers/devise.rb', "config.mailer_sender = '[email protected]'", "config.mailer_sender = '[email protected]'" end |
#update_gemset_in_gemfile ⇒ Object
18 19 20 |
# File 'lib/voyage/app_builder.rb', line 18 def update_gemset_in_gemfile replace_in_file 'Gemfile', '#ruby-gemset', "#ruby-gemset=#{app_name}" end |
#update_test_environment ⇒ Object
414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/voyage/app_builder.rb', line 414 def update_test_environment inject_into_file 'spec/support/factory_girl.rb', before: /^end/ do <<-RUBY.gsub(/^ {6}/, '') # Spring doesn't reload factory_girl config.before(:all) do FactoryGirl.reload end RUBY end template "../templates/rails_helper.rb.erb", "spec/rails_helper.rb", force: true end |
#use_postgres_config_template ⇒ Object
223 224 225 226 |
# File 'lib/suspenders/app_builder.rb', line 223 def use_postgres_config_template template 'postgresql_database.yml.erb', 'config/database.yml', force: true end |
#use_slim ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/voyage/app_builder.rb', line 22 def use_slim if @@accept_defaults || agree?('Would you like to use slim? (Y/n)') @@use_slim = true run 'gem install html2slim' update_application_layout_for_slim else @@use_slim = false end end |