Class: MakeItSo::Rails::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- MakeItSo::Rails::AppBuilder
- Defined in:
- lib/make_it_so/rails/app_builder.rb
Instance Method Summary collapse
- #application_controller ⇒ Object
- #application_record ⇒ Object
- #base_javascripts ⇒ Object
- #base_stylesheets ⇒ Object
- #database_cleaner_rspec ⇒ Object
- #devise_dependency ⇒ Object
- #dotenv ⇒ Object
- #eliminate_byebug ⇒ Object
- #factory_bot_rspec ⇒ Object
- #fix_generators ⇒ Object
- #foundation_dependency ⇒ Object
- #jest ⇒ Object
- #karma ⇒ Object
- #pry_rails_dependency ⇒ Object
- #react ⇒ Object
- #rspec_dependency ⇒ Object
- #shoulda_rspec ⇒ Object
- #valid_attribute_rspec ⇒ Object
- #yarn_install ⇒ Object
Instance Method Details
#application_controller ⇒ Object
7 8 9 10 11 |
# File 'lib/make_it_so/rails/app_builder.rb', line 7 def application_controller inside 'app/controllers' do template 'application_controller.rb' end end |
#application_record ⇒ Object
13 14 15 16 17 |
# File 'lib/make_it_so/rails/app_builder.rb', line 13 def application_record inside 'app/models' do template 'application_record.rb' end end |
#base_javascripts ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/make_it_so/rails/app_builder.rb', line 19 def base_javascripts @generator.gem 'jquery-rails' inside 'app/assets/javascripts' do template 'application.js' jquery_files = "//= require jquery\n" + "//= require jquery_ujs\n" gsub_file 'application.js', "//= require rails-ujs\n", jquery_files end end |
#base_stylesheets ⇒ Object
29 30 31 32 33 |
# File 'lib/make_it_so/rails/app_builder.rb', line 29 def base_stylesheets inside 'app/assets/stylesheets' do template 'application.css' end end |
#database_cleaner_rspec ⇒ Object
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/make_it_so/rails/app_builder.rb', line 177 def database_cleaner_rspec @generator.gem 'database_cleaner', group: [:development, :test] after_bundle do inside 'spec' do inside 'support' do template 'database_cleaner.rb' end end end end |
#devise_dependency ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/make_it_so/rails/app_builder.rb', line 224 def devise_dependency @generator.gem 'devise' after_bundle do generate 'devise:install' generate 'devise:views' generate 'devise user' #note: temporary fix that can be removed once devise progresses #beyond v4.4.3 # https://github.com/plataformatec/devise/pull/4869/files inside 'config/initializers' do insert_into_file 'devise.rb', after: "Devise.setup do |config|" do " config.secret_key = Rails.application.secret_key_base\n" end end if [:rspec] inside 'spec' do directory 'features' inside 'support' do insert_into_file 'factory_bot.rb', after: "FactoryBot.define do\n" do snippet('user_factory.rb') end template 'devise_controller_spec.rb' end end end route "root 'homes\#index'" end end |
#dotenv ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/make_it_so/rails/app_builder.rb', line 124 def dotenv @generator.gem 'dotenv-rails', group: [:development, :test] template '.env' template '.env.example' append_to_file '.gitignore' do ".env\n" end end |
#eliminate_byebug ⇒ Object
45 46 47 48 |
# File 'lib/make_it_so/rails/app_builder.rb', line 45 def eliminate_byebug both_lines = /^[[:space:]]*# Call 'byebug'.*gem 'byebug'.*?$\n/m gsub_file 'Gemfile', both_lines, "\n" end |
#factory_bot_rspec ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/make_it_so/rails/app_builder.rb', line 160 def factory_bot_rspec @generator.gem 'factory_bot', group: [:development, :test] after_bundle do inside 'spec' do insert_into_file 'rails_helper.rb', after: rails_helper_insertion_hook do "require File.join(File.dirname(__FILE__), 'support/factory_bot')\n" end inside 'support' do template 'factory_bot.rb' end end end end |
#fix_generators ⇒ Object
39 40 41 42 43 |
# File 'lib/make_it_so/rails/app_builder.rb', line 39 def fix_generators inject_into_class 'config/application.rb', 'Application' do snippet('application_generator.rb') end end |
#foundation_dependency ⇒ Object
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/make_it_so/rails/app_builder.rb', line 261 def foundation_dependency @generator.gem 'foundation-rails', '~> 6.5' after_bundle do generate 'foundation:install foundation' # foundation install always messes with the JS manifest remove_file 'app/views/layouts/foundation.html.erb' inside 'app/assets/javascripts' do remove_file 'application.js' template 'application.foundation.js', 'application.js' end # foundation-rails generates an application layout so we # must remove it remove_file 'app/views/layouts/foundation.html.erb' end end |
#jest ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/make_it_so/rails/app_builder.rb', line 106 def jest after_bundle do add_test_dependency_snippets( ["js_jest_testing_deps.json", "js_enzyme_testing_deps.json"] ) create_enzyme_config remove_file '.babelrc' remove_file 'babel.config.js' template 'babel.config.js' end end |
#karma ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/make_it_so/rails/app_builder.rb', line 82 def karma after_bundle do add_test_dependency_snippets( ["js_karma_jasmine_testing_deps.json", "js_enzyme_testing_deps.json"] ) create_enzyme_config template 'karma.conf.js' inside 'spec/javascript' do template 'exampleTest.js' template 'testHelper.js' end append_to_file '.gitignore' do "coverage/*\n" end remove_file '.babelrc' remove_file 'babel.config.js' template 'babel.config.js' end end |
#pry_rails_dependency ⇒ Object
35 36 37 |
# File 'lib/make_it_so/rails/app_builder.rb', line 35 def pry_rails_dependency @generator.gem 'pry-rails', group: [:development, :test] end |
#react ⇒ Object
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 |
# File 'lib/make_it_so/rails/app_builder.rb', line 50 def react @generator.gem 'webpacker', '~> 3.3' after_bundle do rake 'webpacker:install' rake 'webpacker:install:react' remove_file 'app/javascript/packs/application.js' remove_file 'app/javascript/packs/hello_react.jsx' unparsed_json = snippet('react_dependencies.json') parsed_json = JSON.parse(unparsed_json) modify_json(package_json_file) do |json| ["dependencies", "devDependencies"].each do |key| json[key] ||= {} json[key].merge!(parsed_json[key]) end json["scripts"] ||= {} json["scripts"]["start"] = "./bin/webpack-dev-server" json["dependencies"].delete("babel-preset-react") end inside 'app/javascript/packs' do copy_file 'new_application.js', 'application.js' remove_file 'new_application.js' end end end |
#rspec_dependency ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/make_it_so/rails/app_builder.rb', line 134 def rspec_dependency @generator.gem 'rspec-rails', '3.8.2', group: [:development, :test] @generator.gem 'capybara', group: [:development, :test] @generator.gem 'launchy', group: [:development, :test] after_bundle do if ![:skip_spring] #stop spring in case it is running - it will hang #https://github.com/rails/rails/issues/13381 run 'spring stop' end generate 'rspec:install' inside 'spec' do empty_directory 'support' end inside 'spec' do insert_into_file 'rails_helper.rb', after: rails_helper_insertion_hook do "require 'capybara/rspec'\n" end end end end |
#shoulda_rspec ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/make_it_so/rails/app_builder.rb', line 205 def shoulda_rspec @generator.gem 'shoulda-matchers', group: [:development, :test], require: false after_bundle do inside 'spec' do insert_into_file 'rails_helper.rb', after: rails_helper_insertion_hook do "require File.join(File.dirname(__FILE__), 'support/shoulda')\n" end inside 'support' do template 'shoulda.rb' end end end end |
#valid_attribute_rspec ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/make_it_so/rails/app_builder.rb', line 188 def valid_attribute_rspec @generator.gem 'valid_attribute', group: [:development, :test] after_bundle do inside 'spec' do insert_into_file 'rails_helper.rb', after: rails_helper_insertion_hook do "require File.join(File.dirname(__FILE__), 'support/valid_attribute')\n" end inside 'support' do template 'valid_attribute.rb' end end end end |
#yarn_install ⇒ Object
120 121 122 |
# File 'lib/make_it_so/rails/app_builder.rb', line 120 def yarn_install run 'yarn install' end |