Class: Suspenders::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Suspenders::AppBuilder
- Extended by:
- Forwardable
- Includes:
- Actions
- Defined in:
- lib/suspenders/app_builder.rb
Instance Method Summary collapse
- #configure_action_mailer ⇒ Object
- #configure_action_mailer_in_specs ⇒ Object
- #configure_generators ⇒ Object
- #configure_i18n_for_missing_translations ⇒ Object
- #configure_local_mail ⇒ Object
- #configure_locales_and_time_zone ⇒ Object
- #configure_quiet_assets ⇒ Object
- #copy_dotfiles ⇒ Object
- #copy_miscellaneous_files ⇒ Object
- #create_database ⇒ Object
- #create_deploy_script ⇒ Object
- #create_heroku_apps(flags) ⇒ Object
- #customize_error_pages ⇒ Object
- #disallow_wrapping_parameters ⇒ Object
- #enable_rack_canonical_host ⇒ Object
- #enable_rack_deflater ⇒ Object
- #gemfile ⇒ Object
- #gitignore ⇒ Object
- #provide_setup_script ⇒ Object
- #raise_on_delivery_errors ⇒ Object
- #raise_on_missing_assets_in_test ⇒ Object
- #raise_on_unpermitted_parameters ⇒ Object
- #readme ⇒ Object
- #remove_config_comment_lines ⇒ Object
- #remove_routes_comment_lines ⇒ Object
- #replace_default_puma_configuration ⇒ Object
- #replace_gemfile(path) ⇒ Object
- #ruby_version ⇒ Object
- #set_test_delivery_method ⇒ Object
- #set_up_forego ⇒ Object
- #setup_asset_host ⇒ Object
- #setup_default_directories ⇒ Object
- #setup_rack_mini_profiler ⇒ Object
- #setup_rakefile ⇒ Object
- #setup_secret_token ⇒ Object
- #use_postgres_config_template ⇒ Object
Methods included from Actions
#action_mailer_asset_host, #action_mailer_host, #configure_environment, #expand_json, #replace_in_file
Instance Method Details
#configure_action_mailer ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/suspenders/app_builder.rb', line 193 def configure_action_mailer action_mailer_host "development", %{"localhost:3000"} action_mailer_asset_host "development", %{"http://localhost:3000"} action_mailer_host "test", %{"www.example.com"} action_mailer_asset_host "test", %{"http://www.example.com"} action_mailer_host "production", %{ENV.fetch("APPLICATION_HOST")} action_mailer_asset_host( "production", %{ENV.fetch("ASSET_HOST", ENV.fetch("APPLICATION_HOST"))}, ) end |
#configure_action_mailer_in_specs ⇒ Object
176 177 178 |
# File 'lib/suspenders/app_builder.rb', line 176 def configure_action_mailer_in_specs copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb' end |
#configure_generators ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/suspenders/app_builder.rb', line 81 def configure_generators config = "\nconfig.generators do |generate|\n generate.helper false\n generate.javascripts 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" |
#configure_i18n_for_missing_translations ⇒ Object
171 172 173 174 |
# File 'lib/suspenders/app_builder.rb', line 171 def configure_i18n_for_missing_translations raise_on_missing_translations_in("development") raise_on_missing_translations_in("test") end |
#configure_local_mail ⇒ Object
99 100 101 |
# File 'lib/suspenders/app_builder.rb', line 99 def configure_local_mail copy_file "email.rb", "config/initializers/email.rb" end |
#configure_locales_and_time_zone ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/suspenders/app_builder.rb', line 180 def configure_locales_and_time_zone remove_file "config/locales/en.yml" template "config_locales_it.yml.erb", "config/locales/it.yml" config = "config.i18n.available_locales = [:en, :it]\nconfig.i18n.default_locale = :it\nconfig.time_zone = 'Rome'\n RUBY\n\n inject_into_class 'config/application.rb', 'Application', config\nend\n" |
#configure_quiet_assets ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/suspenders/app_builder.rb', line 68 def configure_quiet_assets config = "config.assets.quiet = true\n RUBY\n\n inject_into_class \"config/application.rb\", \"Application\", config\nend\n" |
#copy_dotfiles ⇒ Object
237 238 239 |
# File 'lib/suspenders/app_builder.rb', line 237 def copy_dotfiles directory("dotfiles", ".") end |
#copy_miscellaneous_files ⇒ Object
264 265 266 267 268 |
# File 'lib/suspenders/app_builder.rb', line 264 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_database ⇒ Object
153 154 155 |
# File 'lib/suspenders/app_builder.rb', line 153 def create_database bundle_command "exec rails db:create db:migrate" end |
#create_deploy_script ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/suspenders/app_builder.rb', line 246 def create_deploy_script copy_file "bin_deploy", "bin/deploy" instructions = "\n## Deploying\n\nIf you have previously run the `./bin/setup` script,\nyou can deploy to staging and production with:\n\n% ./bin/deploy staging\n% ./bin/deploy production\n MARKDOWN\n\n append_file \"README.md\", instructions\n run \"chmod a+x bin/deploy\"\nend\n" |
#create_heroku_apps(flags) ⇒ Object
241 242 243 244 |
# File 'lib/suspenders/app_builder.rb', line 241 def create_heroku_apps(flags) create_staging_heroku_app(flags) create_production_heroku_app(flags) end |
#customize_error_pages ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/suspenders/app_builder.rb', line 270 def customize_error_pages =" <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 path = \"public/\#{page}.html\"\n if File.exist?(path)\n inject_into_file path, meta_tags, after: \"<head>\\n\"\n replace_in_file path, /<!--.+-->\\n/, ''\n end\n end\nend\n" |
#disallow_wrapping_parameters ⇒ Object
144 145 146 |
# File 'lib/suspenders/app_builder.rb', line 144 def disallow_wrapping_parameters remove_file "config/initializers/wrap_parameters.rb" end |
#enable_rack_canonical_host ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/suspenders/app_builder.rb', line 103 def enable_rack_canonical_host config = "\n if ENV.fetch(\"HEROKU_APP_NAME\", \"\").include?(\"staging-pr-\")\nENV[\"APPLICATION_HOST\"] = ENV[\"HEROKU_APP_NAME\"] + \".herokuapp.com\"\n end\n\n config.middleware.use Rack::CanonicalHost, ENV.fetch(\"APPLICATION_HOST\")\n RUBY\n\n configure_environment \"production\", config\nend\n" |
#enable_rack_deflater ⇒ Object
116 117 118 |
# File 'lib/suspenders/app_builder.rb', line 116 def enable_rack_deflater configure_environment "production", "config.middleware.use Rack::Deflater" end |
#gemfile ⇒ Object
32 33 34 |
# File 'lib/suspenders/app_builder.rb', line 32 def gemfile template "Gemfile.erb", "Gemfile" end |
#gitignore ⇒ Object
28 29 30 |
# File 'lib/suspenders/app_builder.rb', line 28 def gitignore copy_file "suspenders_gitignore", ".gitignore" end |
#provide_setup_script ⇒ Object
76 77 78 79 |
# File 'lib/suspenders/app_builder.rb', line 76 def provide_setup_script template "bin_setup", "bin/setup", force: true run "chmod a+x bin/setup" end |
#raise_on_delivery_errors ⇒ Object
47 48 49 50 |
# File 'lib/suspenders/app_builder.rb', line 47 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
43 44 45 |
# File 'lib/suspenders/app_builder.rb', line 43 def raise_on_missing_assets_in_test configure_environment "test", "config.assets.raise_runtime_errors = true" end |
#raise_on_unpermitted_parameters ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/suspenders/app_builder.rb', line 60 def raise_on_unpermitted_parameters config = "config.action_controller.action_on_unpermitted_parameters = :raise\n RUBY\n\n inject_into_class \"config/application.rb\", \"Application\", config\nend\n" |
#readme ⇒ Object
24 25 26 |
# File 'lib/suspenders/app_builder.rb', line 24 def readme template 'README.md.erb', 'README.md' end |
#remove_config_comment_lines ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/suspenders/app_builder.rb', line 286 def remove_config_comment_lines config_files = [ "application.rb", "environment.rb", "environments/development.rb", "environments/production.rb", "environments/test.rb", ] config_files.each do |config_file| path = File.join(destination_root, "config/#{config_file}") accepted_content = File.readlines(path).reject do |line| line =~ /^.*#.*$/ || line =~ /^$\n/ end File.open(path, "w") do |file| accepted_content.each { |line| file.puts line } end end end |
#remove_routes_comment_lines ⇒ Object
308 309 310 311 312 |
# File 'lib/suspenders/app_builder.rb', line 308 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 |
#replace_default_puma_configuration ⇒ Object
205 206 207 |
# File 'lib/suspenders/app_builder.rb', line 205 def replace_default_puma_configuration copy_file "puma.rb", "config/puma.rb", force: true end |
#replace_gemfile(path) ⇒ Object
157 158 159 160 161 162 163 164 165 |
# File 'lib/suspenders/app_builder.rb', line 157 def replace_gemfile(path) template 'Gemfile.erb', 'Gemfile', force: true do |content| if path content.gsub(%r{gem ['"]welaika-suspenders['"].*}) { |s| %{#{s}, path: "#{path}"} } else content end end end |
#ruby_version ⇒ Object
167 168 169 |
# File 'lib/suspenders/app_builder.rb', line 167 def ruby_version create_file '.ruby-version', "#{Suspenders::RUBY_VERSION}\n" end |
#set_test_delivery_method ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/suspenders/app_builder.rb', line 52 def set_test_delivery_method inject_into_file( "config/environments/development.rb", "\n config.action_mailer.delivery_method = :letter_opener", after: "config.action_mailer.raise_delivery_errors = true", ) end |
#set_up_forego ⇒ Object
209 210 211 |
# File 'lib/suspenders/app_builder.rb', line 209 def set_up_forego copy_file "Procfile", "Procfile" end |
#setup_asset_host ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/suspenders/app_builder.rb', line 120 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"))' if File.exist?("config/initializers/assets.rb") replace_in_file 'config/initializers/assets.rb', "config.assets.version = '1.0'", 'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")' end config = "config.public_file_server.headers = {\n\"Cache-Control\" => \"public, max-age=31557600\",\n }\n EOD\n\n configure_environment(\"production\", config)\nend\n" |
#setup_default_directories ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/suspenders/app_builder.rb', line 213 def setup_default_directories [ 'app/decorators', 'app/forms', 'app/queries', 'app/interactions', 'app/views/pages', 'spec/lib', 'spec/controllers', 'spec/helpers', 'spec/decorators', 'spec/forms', 'spec/queries', 'spec/interactions', 'spec/fixtures', 'spec/factories', 'spec/support/matchers', 'spec/support/mixins', 'spec/support/shared_examples' ].each do |dir| empty_directory_with_keep_file dir end end |
#setup_rack_mini_profiler ⇒ Object
36 37 38 39 40 41 |
# File 'lib/suspenders/app_builder.rb', line 36 def setup_rack_mini_profiler copy_file( "rack_mini_profiler.rb", "config/initializers/rack_mini_profiler.rb", ) end |
#setup_rakefile ⇒ Object
314 315 316 317 318 319 |
# File 'lib/suspenders/app_builder.rb', line 314 def setup_rakefile # NOTE: we named our file `rakefile_template` and not # `Rakefile` because otherwise `copy_file` would copy the # rails `Rakefile` into the project folder. copy_file 'rakefile_template.rb', 'Rakefile', force: true end |
#setup_secret_token ⇒ Object
140 141 142 |
# File 'lib/suspenders/app_builder.rb', line 140 def setup_secret_token template 'secrets.yml', 'config/secrets.yml', force: true end |
#use_postgres_config_template ⇒ Object
148 149 150 151 |
# File 'lib/suspenders/app_builder.rb', line 148 def use_postgres_config_template template 'postgresql_database.yml.erb', 'config/database.yml', force: true end |