Module: Orats::Commands::Project::Rails
- Included in:
- Inventory, Orats::Commands::Playbook, Exec, Role
- Defined in:
- lib/orats/commands/project/rails.rb
Instance Method Summary collapse
- #bundle_binstubs ⇒ Object
- #bundle_install ⇒ Object
- #check_exit_conditions(check_running_processes: true) ⇒ Object
- #create_and_migrate_database ⇒ Object
- #custom_rails_template ⇒ Object
- #generate_favicons ⇒ Object
- #generate_home_page ⇒ Object
- #gsub_postgres_info ⇒ Object
- #gsub_project_path ⇒ Object
- #gsub_readme ⇒ Object
- #gsub_redis_info ⇒ Object
- #migrate_and_seed_database ⇒ Object
- #rails_template(command, flags = '') ⇒ Object
- #run_rake(command) ⇒ Object
- #spring_binstub ⇒ Object
- #template_exist?(template) ⇒ Boolean
Instance Method Details
#bundle_binstubs ⇒ Object
67 68 69 70 71 72 |
# File 'lib/orats/commands/project/rails.rb', line 67 def bundle_binstubs log_task 'Run bundle binstubs for a few gems' run_from @active_path, 'bundle binstubs whenever puma sidekiq backup' git_commit 'Add binstubs for the important gems' end |
#bundle_install ⇒ Object
60 61 62 63 64 65 |
# File 'lib/orats/commands/project/rails.rb', line 60 def bundle_install log_task 'Run bundle install, this may take a while' run_from @active_path, 'bundle install' git_commit 'Add Gemfile.lock' end |
#check_exit_conditions(check_running_processes: true) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/orats/commands/project/rails.rb', line 5 def check_exit_conditions(check_running_processes: true) exit_if_process :not_found, 'rails', 'git' exit_if_process :not_running, 'postgres', 'redis' if check_running_processes exit_if_path_exists exit_if_invalid_template end |
#create_and_migrate_database ⇒ Object
118 119 120 121 |
# File 'lib/orats/commands/project/rails.rb', line 118 def create_and_migrate_database run_rake 'db:create:all db:migrate' git_commit 'Add the database schema file' end |
#custom_rails_template ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/orats/commands/project/rails.rb', line 19 def custom_rails_template log_task 'Run custom rails template' [:custom].include?('://') ? url_to_string([:custom]) : file_to_string([:custom]) rails_template '', "--skip --template #{@options[:custom]}" end |
#generate_favicons ⇒ Object
112 113 114 115 116 |
# File 'lib/orats/commands/project/rails.rb', line 112 def generate_favicons log_task 'Add favicons' run_rake 'orats:favicons' git_commit 'Add favicons' end |
#generate_home_page ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/orats/commands/project/rails.rb', line 87 def generate_home_page kill_spring_servers log_task 'Add pages controller with static page' run_from @active_path, 'bundle exec rails g controller Pages home' gsub_file "#{@active_path}/config/routes.rb", " # root 'welcome#index'" do "root 'pages#home'\n" end gsub_file "#{@active_path}/config/routes.rb", " get 'pages/home'\n\n", '' gsub_file "#{@active_path}/test/controllers/pages_controller_test.rb", '"should get home"', "'expect home page'" run_from @active_path, "rm app/views/pages/home.html.erb" Commands::Common.copy_from_local_gem 'new/rails/app/views/pages/home.html.erb', "#{@active_path}/app/views/pages/home.html.erb" gsub_file "#{@active_path}/app/views/pages/home.html.erb", 'vVERSION', VERSION git_commit 'Add pages controller with home page' end |
#gsub_postgres_info ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/orats/commands/project/rails.rb', line 28 def gsub_postgres_info log_task 'Update the postgres connection details' gsub_file "#{@active_path}/.env", 'DATABASE_HOST: localhost', "DATABASE_HOST: #{@options[:pg_location]}" gsub_file "#{@active_path}/.env", ': postgres', ": #{@options[:pg_username]}" gsub_file "#{@active_path}/.env", ': supersecrets', ": #{@options[:pg_password]}" git_commit 'Update the postgres connection details' end |
#gsub_project_path ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/orats/commands/project/rails.rb', line 45 def gsub_project_path log_task 'Update the project path' gsub_file "#{@active_path}/.env", ': /home/yourname/dev/testproj', ": #{File.expand_path(@active_path)}" git_commit 'Update the project path' end |
#gsub_readme ⇒ Object
53 54 55 56 57 58 |
# File 'lib/orats/commands/project/rails.rb', line 53 def gsub_readme log_task 'Update the readme' gsub_file "#{@active_path}/README.md", 'VERSION', VERSION git_commit 'Update the version' end |
#gsub_redis_info ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/orats/commands/project/rails.rb', line 37 def gsub_redis_info log_task 'Update the redis connection details' gsub_file "#{@active_path}/.env", 'HE_PASSWORD: ""', "HE_PASSWORD: #{@options[:redis_password]}" gsub_file "#{@active_path}/.env", 'CACHE_HOST: localhost', "CACHE_HOST: #{@options[:redis_location]}" git_commit 'Update the redis connection details' end |
#migrate_and_seed_database ⇒ Object
123 124 125 126 |
# File 'lib/orats/commands/project/rails.rb', line 123 def migrate_and_seed_database run_rake 'db:migrate db:seed' git_commit 'Update the database schema file' end |
#rails_template(command, flags = '') ⇒ Object
12 13 14 15 16 17 |
# File 'lib/orats/commands/project/rails.rb', line 12 def rails_template(command, flags = '') orats_template = "--template #{base_path}/templates/#{command}.rb" run "rails new #{@active_path} #{flags} --skip-bundle #{orats_template unless command.empty?}" yield if block_given? end |
#run_rake(command) ⇒ Object
81 82 83 84 85 |
# File 'lib/orats/commands/project/rails.rb', line 81 def run_rake(command) log_task 'Run rake command' run_from @active_path, "bundle exec rake #{command}" end |
#spring_binstub ⇒ Object
74 75 76 77 78 79 |
# File 'lib/orats/commands/project/rails.rb', line 74 def spring_binstub log_task 'Run spring binstub' run_from @active_path, 'bundle exec spring binstub --all' git_commit 'Add spring binstubs for all of the bins' end |
#template_exist?(template) ⇒ Boolean
128 129 130 |
# File 'lib/orats/commands/project/rails.rb', line 128 def template_exist?(template) Exec::PROJECT_TEMPLATES.include?(template.to_sym) end |