Module: Orats::Commands::New::Rails
- Included in:
- Exec
- Defined in:
- lib/orats/commands/new/rails.rb
Overview
helper functions for the new::exec class
Instance Method Summary collapse
- #bundle_binstubs ⇒ Object
- #bundle_install ⇒ Object
- #check_exit_conditions ⇒ Object
- #create_and_migrate_database ⇒ Object
- #custom_rails_template ⇒ Object
- #generate_favicons ⇒ Object
- #generate_home_page ⇒ Object
- #gsub_app_path ⇒ Object
- #gsub_postgres_info ⇒ Object
- #gsub_puma ⇒ Object
- #gsub_readme ⇒ Object
- #gsub_redis_info ⇒ Object
- #migrate_and_seed_database ⇒ Object
- #orats_rails_template ⇒ Object
- #rails_template(command, flags = '') ⇒ Object
- #rails_template_actions ⇒ Object
- #spring_binstub ⇒ Object
- #template_exist?(template) ⇒ Boolean
Instance Method Details
#bundle_binstubs ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/orats/commands/new/rails.rb', line 120 def bundle_binstubs task 'Run bundle binstubs for a few gems' run_from @target_path, "bundle binstubs whenever #{@options[:backend]} sidekiq" commit 'Add binstubs for the important gems' end |
#bundle_install ⇒ Object
113 114 115 116 117 118 |
# File 'lib/orats/commands/new/rails.rb', line 113 def bundle_install task 'Run bundle install, this may take a while' run_from @target_path, 'bundle install' commit 'Add Gemfile.lock' end |
#check_exit_conditions ⇒ Object
6 7 8 9 10 11 |
# File 'lib/orats/commands/new/rails.rb', line 6 def check_exit_conditions exit_if_path_exists exit_if_invalid_template exit_if_invalid_system exit_if_database_exists end |
#create_and_migrate_database ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/orats/commands/new/rails.rb', line 153 def create_and_migrate_database task 'Create and migrate the database' create_database run_rake 'db:migrate' commit 'Add the database schema file' end |
#custom_rails_template ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/orats/commands/new/rails.rb', line 28 def custom_rails_template task 'Add custom template' rails_template '', "--skip --template #{@options[:custom]}" run_from @target_path, 'rm -rf app/assets/stylesheets/application.css' commit 'Add custom template' end |
#generate_favicons ⇒ Object
147 148 149 150 151 |
# File 'lib/orats/commands/new/rails.rb', line 147 def generate_favicons run_rake 'orats:favicons' commit 'Add favicons' end |
#generate_home_page ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/orats/commands/new/rails.rb', line 135 def generate_home_page kill_spring_servers task 'Add pages controller with static page' run_from @target_path, 'bundle exec rails g controller Pages home' gsub_home_page copy_home_page_views commit 'Add pages controller with home page' end |
#gsub_app_path ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/orats/commands/new/rails.rb', line 84 def gsub_app_path task 'Update the app path' gsub_file "#{@target_path}/.env", ": '/tmp/yourapp'", ": '#{File.expand_path(@target_path)}'" commit 'Update the app path' end |
#gsub_postgres_info ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/orats/commands/new/rails.rb', line 53 def gsub_postgres_info task 'Update the DATABASE_URL' unless [:pg_password].empty? gsub_file "#{@target_path}/.env", 'db_user', "db_user:#{@options[:pg_password]}" end gsub_file "#{@target_path}/.env", 'db_location', [:pg_location] gsub_file "#{@target_path}/.env", 'db_port', [:pg_port] gsub_file "#{@target_path}/.env", 'db_user', [:pg_username] commit 'Update the DATABASE_URL' end |
#gsub_puma ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/orats/commands/new/rails.rb', line 101 def gsub_puma task 'Update files for switching to puma' gsub_file "#{@target_path}/Procfile", 'unicorn -c config/unicorn.rb', 'puma -C config/puma.rb' gsub_file "#{@target_path}/Gemfile", "gem 'unicorn'", "#gem 'unicorn'" gsub_file "#{@target_path}/Gemfile", "#gem 'puma'", "gem 'puma'" commit 'Switch from unicorn to puma' end |
#gsub_readme ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/orats/commands/new/rails.rb', line 93 def gsub_readme task 'Update the readme' gsub_file "#{@target_path}/README.md", 'VERSION', VERSION commit 'Update the readme' end |
#gsub_redis_info ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/orats/commands/new/rails.rb', line 69 def gsub_redis_info task 'Update the CACHE_URL' unless [:redis_password].empty? gsub_file "#{@target_path}/.env", '//', "//#{@options[:redis_password]}@" end gsub_file "#{@target_path}/.env", 'cache_location', [:redis_location] gsub_file "#{@target_path}/.env", 'cache_port', [:redis_port] commit 'Update the CACHE_URL' end |
#migrate_and_seed_database ⇒ Object
162 163 164 165 166 |
# File 'lib/orats/commands/new/rails.rb', line 162 def migrate_and_seed_database run_rake 'db:migrate db:seed' commit 'Update the database schema file' end |
#orats_rails_template ⇒ Object
22 23 24 25 26 |
# File 'lib/orats/commands/new/rails.rb', line 22 def orats_rails_template rails_template [:template], '--skip ' do migrate_and_seed_database end end |
#rails_template(command, flags = '') ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/orats/commands/new/rails.rb', line 13 def rails_template(command, flags = '') orats_template = "--template #{base_path}/templates/#{command}.rb" run "rails new #{@target_path} #{flags} --skip-bundle " + \ " #{orats_template unless command.empty?}" yield if block_given? end |
#rails_template_actions ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/orats/commands/new/rails.rb', line 38 def rails_template_actions gsub_postgres_info gsub_redis_info gsub_readme gsub_puma if [:backend] == 'puma' bundle_install bundle_binstubs spring_binstub create_and_migrate_database generate_home_page generate_favicons end |
#spring_binstub ⇒ Object
128 129 130 131 132 133 |
# File 'lib/orats/commands/new/rails.rb', line 128 def spring_binstub task 'Run spring binstub' run_from @target_path, 'bundle exec spring binstub --all' commit 'Add spring binstubs for all of the bins' end |
#template_exist?(template) ⇒ Boolean
168 169 170 |
# File 'lib/orats/commands/new/rails.rb', line 168 def template_exist?(template) Exec::AVAILABLE_TEMPLATES.include?(template.to_sym) end |