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_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
186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/suspenders/app_builder.rb', line 186 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
169 170 171 |
# File 'lib/suspenders/app_builder.rb', line 169 def configure_action_mailer_in_specs copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb' end |
#configure_generators ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/suspenders/app_builder.rb', line 79 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
164 165 166 167 |
# File 'lib/suspenders/app_builder.rb', line 164 def configure_i18n_for_missing_translations raise_on_missing_translations_in("development") raise_on_missing_translations_in("test") end |
#configure_local_mail ⇒ Object
97 98 99 |
# File 'lib/suspenders/app_builder.rb', line 97 def configure_local_mail copy_file "email.rb", "config/initializers/email.rb" end |
#configure_locales_and_time_zone ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/suspenders/app_builder.rb', line 173 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
66 67 68 69 70 71 72 |
# File 'lib/suspenders/app_builder.rb', line 66 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
230 231 232 |
# File 'lib/suspenders/app_builder.rb', line 230 def copy_dotfiles directory("dotfiles", ".") end |
#copy_miscellaneous_files ⇒ Object
239 240 241 242 |
# File 'lib/suspenders/app_builder.rb', line 239 def copy_miscellaneous_files copy_file "errors.rb", "config/initializers/errors.rb" copy_file "json_encoding.rb", "config/initializers/json_encoding.rb" end |
#create_database ⇒ Object
146 147 148 |
# File 'lib/suspenders/app_builder.rb', line 146 def create_database bundle_command "exec rails db:create db:migrate" end |
#create_heroku_apps(flags) ⇒ Object
234 235 236 237 |
# File 'lib/suspenders/app_builder.rb', line 234 def create_heroku_apps(flags) create_staging_heroku_app(flags) create_production_heroku_app(flags) end |
#customize_error_pages ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/suspenders/app_builder.rb', line 244 def customize_error_pages =" <meta charset=\"utf-8\" />\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
137 138 139 |
# File 'lib/suspenders/app_builder.rb', line 137 def disallow_wrapping_parameters remove_file "config/initializers/wrap_parameters.rb" end |
#enable_rack_canonical_host ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/suspenders/app_builder.rb', line 101 def enable_rack_canonical_host config = " config.middleware.use Rack::CanonicalHost, ENV.fetch(\"APPLICATION_HOST\")\n RUBY\n\n configure_environment \"production\", config\nend\n" |
#enable_rack_deflater ⇒ Object
109 110 111 |
# File 'lib/suspenders/app_builder.rb', line 109 def enable_rack_deflater configure_environment "production", "config.middleware.use Rack::Deflater" end |
#gemfile ⇒ Object
30 31 32 |
# File 'lib/suspenders/app_builder.rb', line 30 def gemfile template "Gemfile.erb", "Gemfile" end |
#gitignore ⇒ Object
26 27 28 |
# File 'lib/suspenders/app_builder.rb', line 26 def gitignore copy_file "suspenders_gitignore", ".gitignore" end |
#provide_setup_script ⇒ Object
74 75 76 77 |
# File 'lib/suspenders/app_builder.rb', line 74 def provide_setup_script template "bin_setup", "bin/setup", force: true run "chmod a+x bin/setup" end |
#raise_on_delivery_errors ⇒ Object
45 46 47 48 |
# File 'lib/suspenders/app_builder.rb', line 45 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
41 42 43 |
# File 'lib/suspenders/app_builder.rb', line 41 def raise_on_missing_assets_in_test configure_environment "test", "config.assets.raise_runtime_errors = true" end |
#raise_on_unpermitted_parameters ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/suspenders/app_builder.rb', line 58 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
22 23 24 |
# File 'lib/suspenders/app_builder.rb', line 22 def readme template 'README.md.erb', 'README.md' end |
#remove_config_comment_lines ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/suspenders/app_builder.rb', line 259 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
281 282 283 284 285 |
# File 'lib/suspenders/app_builder.rb', line 281 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
198 199 200 |
# File 'lib/suspenders/app_builder.rb', line 198 def replace_default_puma_configuration copy_file "puma.rb", "config/puma.rb", force: true end |
#replace_gemfile(path) ⇒ Object
150 151 152 153 154 155 156 157 158 |
# File 'lib/suspenders/app_builder.rb', line 150 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
160 161 162 |
# File 'lib/suspenders/app_builder.rb', line 160 def ruby_version create_file '.ruby-version', "#{Suspenders::RUBY_VERSION}\n" end |
#set_test_delivery_method ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/suspenders/app_builder.rb', line 50 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
202 203 204 |
# File 'lib/suspenders/app_builder.rb', line 202 def set_up_forego copy_file "Procfile", "Procfile" end |
#setup_asset_host ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/suspenders/app_builder.rb', line 113 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
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/suspenders/app_builder.rb', line 206 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
34 35 36 37 38 39 |
# File 'lib/suspenders/app_builder.rb', line 34 def setup_rack_mini_profiler copy_file( "rack_mini_profiler.rb", "config/initializers/rack_mini_profiler.rb", ) end |
#setup_rakefile ⇒ Object
287 288 289 290 291 292 |
# File 'lib/suspenders/app_builder.rb', line 287 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
133 134 135 |
# File 'lib/suspenders/app_builder.rb', line 133 def setup_secret_token template 'secrets.yml', 'config/secrets.yml', force: true end |
#use_postgres_config_template ⇒ Object
141 142 143 144 |
# File 'lib/suspenders/app_builder.rb', line 141 def use_postgres_config_template template 'postgresql_database.yml.erb', 'config/database.yml', force: true end |