Class: Suspenders::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Suspenders::AppBuilder
- Includes:
- Actions
- Defined in:
- lib/suspenders/app_builder.rb
Instance Method Summary collapse
- #add_email_validator ⇒ Object
- #add_jquery_ui ⇒ Object
- #blacklist_active_record_attributes ⇒ Object
- #configure_action_mailer ⇒ Object
- #configure_capybara_webkit ⇒ Object
- #configure_rack_timeout ⇒ Object
- #configure_rspec ⇒ Object
- #configure_smtp ⇒ Object
- #configure_strong_parameters ⇒ Object
- #configure_time_formats ⇒ Object
- #configure_time_zone ⇒ Object
- #copy_miscellaneous_files ⇒ Object
- #create_application_layout ⇒ Object
- #create_common_javascripts ⇒ Object
- #create_database ⇒ Object
- #create_github_repo(repo_name) ⇒ Object
- #create_heroku_apps ⇒ Object
- #create_partials_directory ⇒ Object
- #create_shared_flashes ⇒ Object
- #create_shared_javascripts ⇒ Object
- #customize_error_pages ⇒ Object
- #disable_xml_params ⇒ Object
- #enable_database_cleaner ⇒ Object
- #enable_factory_girl_syntax ⇒ Object
- #generate_clearance ⇒ Object
- #generate_rspec ⇒ Object
- #gitignore_files ⇒ Object
- #init_git ⇒ Object
- #initialize_on_precompile ⇒ Object
- #provide_setup_script ⇒ Object
- #raise_delivery_errors ⇒ Object
- #readme ⇒ Object
- #remove_public_index ⇒ Object
- #remove_rails_logo_image ⇒ Object
- #remove_routes_comment_lines ⇒ Object
- #replace_gemfile ⇒ Object
- #set_ruby_to_version_being_used ⇒ Object
- #setup_default_rake_task ⇒ Object
- #setup_foreman ⇒ Object
- #setup_staging_environment ⇒ Object
- #setup_stylesheets ⇒ Object
- #test_factories_first ⇒ Object
- #use_postgres_config_template ⇒ Object
Methods included from Actions
#action_mailer_host, #concat_file, #download_file, #replace_in_file
Instance Method Details
#add_email_validator ⇒ Object
275 276 277 |
# File 'lib/suspenders/app_builder.rb', line 275 def add_email_validator copy_file 'email_validator.rb', 'app/validators/email_validator.rb' end |
#add_jquery_ui ⇒ Object
86 87 88 89 |
# File 'lib/suspenders/app_builder.rb', line 86 def add_jquery_ui inject_into_file 'app/assets/javascripts/application.js', "//= require jquery-ui\n", :before => '//= require_tree .' end |
#blacklist_active_record_attributes ⇒ Object
150 151 152 153 154 |
# File 'lib/suspenders/app_builder.rb', line 150 def blacklist_active_record_attributes replace_in_file 'config/application.rb', 'config.active_record.whitelist_attributes = true', 'config.active_record.whitelist_attributes = false' end |
#configure_action_mailer ⇒ Object
177 178 179 180 181 182 |
# File 'lib/suspenders/app_builder.rb', line 177 def configure_action_mailer action_mailer_host 'development', "#{app_name}.local" action_mailer_host 'test', 'www.example.com' action_mailer_host 'staging', "staging.#{app_name}.com" action_mailer_host 'production', "#{app_name}.com" end |
#configure_capybara_webkit ⇒ Object
188 189 190 191 192 |
# File 'lib/suspenders/app_builder.rb', line 188 def append_file 'spec/spec_helper.rb' do "\nCapybara.javascript_driver = :webkit" end end |
#configure_rack_timeout ⇒ Object
173 174 175 |
# File 'lib/suspenders/app_builder.rb', line 173 def configure_rack_timeout copy_file 'rack_timeout.rb', 'config/initializers/rack_timeout.rb' end |
#configure_rspec ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/suspenders/app_builder.rb', line 118 def configure_rspec remove_file '.rspec' copy_file 'rspec', '.rspec' prepend_file 'spec/spec_helper.rb', simplecov_init replace_in_file 'spec/spec_helper.rb', '# config.mock_with :mocha', 'config.mock_with :mocha' rspec_expect_syntax = <<-RUBY config.expect_with :rspec do |c| c.syntax = :expect end RUBY config = <<-RUBY config.generators do |generate| generate.test_framework :rspec generate.helper false generate.stylesheets false generate.javascript_engine false generate.view_specs false end RUBY inject_into_file 'spec/spec_helper.rb', rspec_expect_syntax, :after => 'RSpec.configure do |config|' inject_into_class 'config/application.rb', 'Application', config end |
#configure_smtp ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/suspenders/app_builder.rb', line 36 def configure_smtp copy_file 'smtp.rb', 'config/initializers/smtp.rb' prepend_file 'config/environments/production.rb', "require Rails.root.join('config/initializers/smtp')" 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_strong_parameters ⇒ Object
156 157 158 |
# File 'lib/suspenders/app_builder.rb', line 156 def configure_strong_parameters copy_file 'strong_parameters.rb', 'config/initializers/strong_parameters.rb' end |
#configure_time_formats ⇒ Object
168 169 170 171 |
# File 'lib/suspenders/app_builder.rb', line 168 def configure_time_formats remove_file 'config/locales/en.yml' copy_file 'config_locales_en.yml', 'config/locales/en.yml' end |
#configure_time_zone ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/suspenders/app_builder.rb', line 160 def configure_time_zone config = <<-RUBY config.active_record.default_timezone = :utc RUBY inject_into_class 'config/application.rb', 'Application', config end |
#copy_miscellaneous_files ⇒ Object
249 250 251 |
# File 'lib/suspenders/app_builder.rb', line 249 def copy_miscellaneous_files copy_file 'errors.rb', 'config/initializers/errors.rb' end |
#create_application_layout ⇒ Object
76 77 78 79 80 |
# File 'lib/suspenders/app_builder.rb', line 76 def create_application_layout template 'suspenders_layout.html.erb.erb', 'app/views/layouts/application.html.erb', :force => true end |
#create_common_javascripts ⇒ Object
82 83 84 |
# File 'lib/suspenders/app_builder.rb', line 82 def create_common_javascripts directory 'javascripts', 'app/assets/javascripts' end |
#create_database ⇒ Object
96 97 98 |
# File 'lib/suspenders/app_builder.rb', line 96 def create_database bundle_command 'exec rake db:create' end |
#create_github_repo(repo_name) ⇒ Object
244 245 246 247 |
# File 'lib/suspenders/app_builder.rb', line 244 def create_github_repo(repo_name) path_addition = override_path_for_tests run "#{path_addition} hub create #{repo_name}" end |
#create_heroku_apps ⇒ Object
237 238 239 240 241 242 |
# File 'lib/suspenders/app_builder.rb', line 237 def create_heroku_apps path_addition = override_path_for_tests run "#{path_addition} heroku create #{app_name}-production --remote=production" run "#{path_addition} heroku create #{app_name}-staging --remote=staging" run "#{path_addition} heroku config:add RACK_ENV=staging RAILS_ENV=staging --remote=staging" end |
#create_partials_directory ⇒ Object
64 65 66 |
# File 'lib/suspenders/app_builder.rb', line 64 def create_partials_directory empty_directory 'app/views/application' end |
#create_shared_flashes ⇒ Object
68 69 70 |
# File 'lib/suspenders/app_builder.rb', line 68 def create_shared_flashes copy_file '_flashes.html.erb', 'app/views/application/_flashes.html.erb' end |
#create_shared_javascripts ⇒ Object
72 73 74 |
# File 'lib/suspenders/app_builder.rb', line 72 def create_shared_javascripts copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb' end |
#customize_error_pages ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/suspenders/app_builder.rb', line 253 def customize_error_pages =<<-EOS <meta charset='utf-8' /> <meta name='ROBOTS' content='NOODP' /> EOS =<<-EOS <link href='/assets/application.css' media='all' rel='stylesheet' type='text/css' /> EOS %w(500 404 422).each do |page| inject_into_file "public/#{page}.html", , :after => "<head>\n" replace_in_file "public/#{page}.html", /<style.+>.+<\/style>/mi, .strip replace_in_file "public/#{page}.html", /<!--.+-->\n/, '' end end |
#disable_xml_params ⇒ Object
279 280 281 |
# File 'lib/suspenders/app_builder.rb', line 279 def disable_xml_params copy_file 'disable_xml_params.rb', 'config/initializers/disable_xml_params.rb' end |
#enable_database_cleaner ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/suspenders/app_builder.rb', line 110 def enable_database_cleaner replace_in_file 'spec/spec_helper.rb', 'config.use_transactional_fixtures = true', 'config.use_transactional_fixtures = false' copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb' end |
#enable_factory_girl_syntax ⇒ Object
27 28 29 |
# File 'lib/suspenders/app_builder.rb', line 27 def enable_factory_girl_syntax copy_file 'factory_girl_syntax_rspec.rb', 'spec/support/factory_girl.rb' end |
#generate_clearance ⇒ Object
194 195 196 |
# File 'lib/suspenders/app_builder.rb', line 194 def generate_clearance generate 'clearance:install' end |
#generate_rspec ⇒ Object
184 185 186 |
# File 'lib/suspenders/app_builder.rb', line 184 def generate_rspec generate 'rspec:install' end |
#gitignore_files ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/suspenders/app_builder.rb', line 211 def gitignore_files concat_file 'suspenders_gitignore', '.gitignore' [ 'app/models', 'app/assets/images', 'app/views/pages', 'db/migrate', 'log', 'spec/support', 'spec/lib', 'spec/models', 'spec/views', 'spec/controllers', 'spec/helpers', 'spec/support/matchers', 'spec/support/mixins', 'spec/support/shared_examples' ].each do |dir| empty_directory_with_gitkeep dir end end |
#init_git ⇒ Object
233 234 235 |
# File 'lib/suspenders/app_builder.rb', line 233 def init_git run 'git init' end |
#initialize_on_precompile ⇒ Object
58 59 60 61 62 |
# File 'lib/suspenders/app_builder.rb', line 58 def initialize_on_precompile inject_into_file 'config/application.rb', "\n config.assets.initialize_on_precompile = false", :after => 'config.assets.enabled = true' end |
#provide_setup_script ⇒ Object
22 23 24 25 |
# File 'lib/suspenders/app_builder.rb', line 22 def provide_setup_script copy_file 'bin_setup', 'bin/setup' run 'chmod a+x bin/setup' end |
#raise_delivery_errors ⇒ Object
17 18 19 20 |
# File 'lib/suspenders/app_builder.rb', line 17 def raise_delivery_errors replace_in_file 'config/environments/development.rb', 'raise_delivery_errors = false', 'raise_delivery_errors = true' end |
#readme ⇒ Object
5 6 7 |
# File 'lib/suspenders/app_builder.rb', line 5 def readme template 'README.md.erb', 'README.md' end |
#remove_public_index ⇒ Object
9 10 11 |
# File 'lib/suspenders/app_builder.rb', line 9 def remove_public_index remove_file 'public/index.html' end |
#remove_rails_logo_image ⇒ Object
13 14 15 |
# File 'lib/suspenders/app_builder.rb', line 13 def remove_rails_logo_image remove_file 'app/assets/images/rails.png' end |
#remove_routes_comment_lines ⇒ Object
269 270 271 272 273 |
# File 'lib/suspenders/app_builder.rb', line 269 def remove_routes_comment_lines replace_in_file 'config/routes.rb', /Application\.routes\.draw do.*end/m, "Application.routes.draw do\nend" end |
#replace_gemfile ⇒ Object
100 101 102 103 |
# File 'lib/suspenders/app_builder.rb', line 100 def replace_gemfile remove_file 'Gemfile' copy_file 'Gemfile_clean', 'Gemfile' end |
#set_ruby_to_version_being_used ⇒ Object
105 106 107 108 |
# File 'lib/suspenders/app_builder.rb', line 105 def set_ruby_to_version_being_used inject_into_file 'Gemfile', "\n\nruby '#{RUBY_VERSION}'", after: /source 'https:\/\/rubygems.org'/ end |
#setup_default_rake_task ⇒ Object
283 284 285 286 287 |
# File 'lib/suspenders/app_builder.rb', line 283 def setup_default_rake_task append_file 'Rakefile' do "task(:default).clear\ntask :default => [:spec]" end end |
#setup_foreman ⇒ Object
198 199 200 201 |
# File 'lib/suspenders/app_builder.rb', line 198 def setup_foreman copy_file 'sample.env', '.sample.env' copy_file 'Procfile', 'Procfile' end |
#setup_staging_environment ⇒ Object
51 52 53 54 55 56 |
# File 'lib/suspenders/app_builder.rb', line 51 def setup_staging_environment run 'cp config/environments/production.rb config/environments/staging.rb' prepend_file 'config/environments/staging.rb', "Mail.register_interceptor RecipientInterceptor.new(ENV['EMAIL_RECIPIENTS'])" end |
#setup_stylesheets ⇒ Object
203 204 205 206 207 208 209 |
# File 'lib/suspenders/app_builder.rb', line 203 def setup_stylesheets copy_file 'app/assets/stylesheets/application.css', 'app/assets/stylesheets/application.css.scss' remove_file 'app/assets/stylesheets/application.css' concat_file 'import_scss_styles', 'app/assets/stylesheets/application.css.scss' create_file 'app/assets/stylesheets/_screen.scss' end |
#test_factories_first ⇒ Object
31 32 33 34 |
# File 'lib/suspenders/app_builder.rb', line 31 def test_factories_first copy_file 'factories_spec.rb', 'spec/models/factories_spec.rb' append_file 'Rakefile', factories_spec_rake_task end |
#use_postgres_config_template ⇒ Object
91 92 93 94 |
# File 'lib/suspenders/app_builder.rb', line 91 def use_postgres_config_template template 'postgresql_database.yml.erb', 'config/database.yml', :force => true end |