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

Instance Method Details

#bundle_binstubsObject



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_installObject



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_conditionsObject



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_databaseObject



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_templateObject



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_faviconsObject



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_pageObject



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_pathObject



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_infoObject



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 @options[:pg_password].empty?
    gsub_file "#{@target_path}/.env", 'db_user',
              "db_user:#{@options[:pg_password]}"
  end

  gsub_file "#{@target_path}/.env", 'db_location',
            @options[:pg_location]
  gsub_file "#{@target_path}/.env", 'db_port', @options[:pg_port]
  gsub_file "#{@target_path}/.env", 'db_user', @options[:pg_username]

  commit 'Update the DATABASE_URL'
end

#gsub_pumaObject



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_readmeObject



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_infoObject



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 @options[:redis_password].empty?
    gsub_file "#{@target_path}/.env", '//',
              "//#{@options[:redis_password]}@"
  end

  gsub_file "#{@target_path}/.env", 'cache_location',
            @options[:redis_location]
  gsub_file "#{@target_path}/.env", 'cache_port', @options[:redis_port]

  commit 'Update the CACHE_URL'
end

#migrate_and_seed_databaseObject



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_templateObject



22
23
24
25
26
# File 'lib/orats/commands/new/rails.rb', line 22

def orats_rails_template
  rails_template @options[: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_actionsObject



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 @options[:backend] == 'puma'

  bundle_install
  bundle_binstubs
  spring_binstub

  create_and_migrate_database
  generate_home_page
  generate_favicons
end

#spring_binstubObject



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