|
| 1 | +module Recipes |
| 2 | + class Configuration < Base |
| 3 | + def initialize(template) |
| 4 | + @template = template |
| 5 | + end |
| 6 | + |
| 7 | + def gems |
| 8 | + @template.gem 'rails', '~> 5.0' |
| 9 | + # Model |
| 10 | + @template.gem 'aasm' |
| 11 | + @template.gem 'keynote' |
| 12 | + @template.gem 'paranoia' if @template.yes?('Do you want to use Soft Deletes?') |
| 13 | + # Searchs |
| 14 | + @template.gem 'ransack' if @template.yes?('Do you want to use Ransack?') |
| 15 | + @template.gem 'kaminari' |
| 16 | + @template.gem 'searchkick' if @template.yes?('Are you going to use ElasticSearch?') |
| 17 | + # Emails |
| 18 | + @template.gem 'premailer-rails' |
| 19 | + |
| 20 | + yield if block_given? |
| 21 | + |
| 22 | + @template.gem_group :development, :test do |group| |
| 23 | + group.gem 'bundler-audit', require: false |
| 24 | + group.gem 'byebug' |
| 25 | + group.gem 'rspec-rails' |
| 26 | + group.gem 'spring' |
| 27 | + group.gem 'figaro' |
| 28 | + group.gem 'mailcatcher' |
| 29 | + group.gem 'factory_girl_rails' |
| 30 | + group.gem 'faker' |
| 31 | + group.gem 'listen' |
| 32 | + group.gem 'pry-rails' |
| 33 | + group.gem 'pry-coolline' |
| 34 | + group.gem 'pry-byebug' |
| 35 | + group.gem 'rubocop', require: false |
| 36 | + end |
| 37 | + |
| 38 | + @template.gem_group :development do |group| |
| 39 | + group.gem 'spring-commands-rspec', require: false |
| 40 | + group.gem 'better_errors' |
| 41 | + end |
| 42 | + |
| 43 | + @template.gem_group :test do |group| |
| 44 | + group.gem 'simplecov', require: false |
| 45 | + group.gem 'capybara', require: false |
| 46 | + group.gem 'capybara-webkit', require: false |
| 47 | + group.gem 'database_cleaner', require: false |
| 48 | + group.gem 'fakeredis', require: false |
| 49 | + group.gem 'poltergeist', require: false |
| 50 | + group.gem 'shoulda-matchers', require: false |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + def init_file |
| 55 | + create_application_yml |
| 56 | + create_routes_file |
| 57 | + set_error_handling |
| 58 | + add_rubocop |
| 59 | + end |
| 60 | + |
| 61 | + private |
| 62 | + |
| 63 | + def create_application_yml |
| 64 | + @template.create_file 'config/application.yml' |
| 65 | + @template.create_file 'config/application.yml.example' |
| 66 | + end |
| 67 | + |
| 68 | + def create_routes_file |
| 69 | + @template.remove_file 'config/routes.rb' |
| 70 | + @template.create_file 'config/routes.rb' do <<~RUBY |
| 71 | + Rails.application.routes.draw do |
| 72 | + end |
| 73 | + RUBY |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + def set_error_handling |
| 78 | + @template.insert_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do <<~RUBY |
| 79 | + match '/404', to: 'errors#not_found', via: :all |
| 80 | + match '/500', to: 'errors#internal_error', via: :all |
| 81 | + RUBY |
| 82 | + end |
| 83 | + @template.insert_into_file 'config/application.rb', after: "class Application < Rails::Application\n" do <<~RUBY |
| 84 | + \tconfig.exceptions_app = self.routes |
| 85 | + RUBY |
| 86 | + end |
| 87 | + @template.run 'rails g controller errors not_found internal_error --no-assets --skip-routes --no-controller-specs --no-view-specs --no-helper' |
| 88 | + @template.remove_file 'app/controllers/errors_controller.rb' |
| 89 | + @template.copy_file(File.join(File.dirname(__FILE__), 'controllers', 'errors_controller.rb'), 'app/controllers/errors_controller.rb') |
| 90 | + end |
| 91 | + |
| 92 | + def add_rubocop |
| 93 | + @template.create_file '.rubocop.yml' do <<~CODE |
| 94 | + inherit_from: https://raw.githubusercontent.com/MarsBased/marstyle/master/ruby/.rubocop.yml |
| 95 | + CODE |
| 96 | + end |
| 97 | + end |
| 98 | + |
| 99 | + end |
| 100 | +end |
0 commit comments