generic_app 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eed7416e2a8fe4d4cea0f0f28c5c9f0ab9e2ae3c
4
- data.tar.gz: 4785ed26af66531afd9ac09c9da542a7be4999eb
3
+ metadata.gz: c23639813bb6d1fc0e62f34ad2ea2358285ff162
4
+ data.tar.gz: a79731e198bb7173df2be16edb6c47126fa5e305
5
5
  SHA512:
6
- metadata.gz: 4f86509f577cf802a1db9730d7308fa61376eeaf3395a7eeb70937726a0b3b1b87f1d9d40ac10862286952539269a8343bda84ca8d0404160ead56208d14a9af
7
- data.tar.gz: f3b6d24ca3a84c965ab77705921d7c01b229665041189696e72a27fd2b2c2a5e64be8e7fb7241542aa5fe6aef0a30803d84256c4ccdb073ded5001985c194dad
6
+ metadata.gz: f3f8c5c23b763e4eccaee31320d971946f1d20bea9d037343a8fef1dbe2704083e0e8c39c69f7abc0fe1bde62ebb6f42fe8d74a6b1671ec1ba1e64df4890444c
7
+ data.tar.gz: ba70b483f91585747d5e8785c594223cddbd9d46d8257b14f8c49d8b4448628444032538f0f88b95da99a9c65c8dc6e49d3e7eba1854ff7c566203b4617371c2
data/README.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # GenericApp
2
2
 
3
+ Welcome to GenericApp, the #1 Rails app generator! No other method of starting a Rails app can save you so much time and effort. Stop reinventing the wheel every time you start a new Rails project. User authentication, comprehensive tests, Guard automation, Twitter bootstrap styling, and other features that are desirable in all or most Rails apps are implemented in advance. You get post-installation scripts that consolidate routine multi-step tasks into one step, including the process of setting up your app for PostgreSQL. Outlines of the initial MVC architecture of your new app are also provided. Only GenericApp way gives you a comprehensive Rails app in just a few minutes. If you're not exactly a GenericApp user, then you're not exactly viable at Startup Weekend or 24-hour web site challenges.
4
+ <br><br>
5
+ GenericApp also works for legacy Rails apps. You can incorporate GenericApp's post-installation scripts into a legacy Rails app, including the PostgreSQL setup script and a script that prints out a list of all of the directories and files most relevant to the MVC architecture.
6
+
3
7
  ## Prerequisites
4
8
 
5
- You must have not only Ruby on Rails installed but PostgreSQL installed as well. Everything you need to use GenericApp is pre-installed in my Debian Stable Vagrant Box for Ruby On Rails ( https://github.com/jhsu802701/vagrant_debian_wheezy_rvm ).
9
+ You must have not only Ruby on Rails installed but SQLite and PostgreSQL installed as well. Everything you need to use the GenericApp gem is pre-installed in my Debian Stable Vagrant Box for Ruby On Rails ( https://github.com/jhsu802701/vagrant-debian-jessie-rvm ).
6
10
 
7
11
  ## Installation
8
12
 
9
- Install it yourself with the command:
13
+ Install the GenericApp gem with the command:
10
14
 
11
15
  $ gem install generic_app
12
16
 
@@ -14,13 +18,13 @@ Install it yourself with the command:
14
18
 
15
19
  ### Creating A Rails App
16
20
 
17
- Go to the directory where you keep your Rails projects and enter the command "generic_app". You will be asked to select the name of the directory you wish to use for your Rails project, and you will be asked whether you wish to use the SQLite or PostgreSQL database in your development environment. If you choose PostgreSQL, you will be asked for database parameters.
21
+ Go to the directory where you keep your Rails projects and enter the command "generic_app". You will be asked to select the name of the directory you wish to use for your Rails project.
18
22
  <br><br>
19
- After you have provided all of the necessary parameters, your generic Rails project will not only be created for you but automatically tested as well. All this takes a few minutes instead of several long and grueling hours.
23
+ After you have provided all of the necessary parameters, your generic Rails project will not only be created for you but automatically tested as well. This takes a few minutes instead of several long and grueling hours.
20
24
 
21
25
  ### Adding Generic App Features To An Existing Project
22
26
 
23
- Go to the parent of the app's root directory. Enter the command "generic_app_add". You will be shown a list of all sub-directories within your present working directory. Pick the sub-directory corresponding to your target app. The Bash scripts and the list of directories and files within the project will be added. Please note that you may need to revise the test.sh script created in the project, which is designed around the railstutorial.org Sample App.
27
+ Go to the parent of the app's root directory. Enter the command "generic_app_add". You will be shown a list of all sub-directories within your present working directory. Pick the sub-directory corresponding to your target app. The Bash scripts and the list of directories and files within the project will be added. Please note that you may need to revise some of the scripts provided by GenericApp, which is designed around the railstutorial.org Sample App.
24
28
 
25
29
  ## What's the point?
26
30
 
@@ -29,46 +33,33 @@ elements and features that nearly all Rails apps require. Instead of spending h
29
33
  can spend more of your time on the more advanced features and capabilities that are unique to your specific Rails
30
34
  app. Modifying a generic app takes far less time than creating an app completely from scratch.
31
35
  <br><br>
32
- Creating a basic generic web site with user capability and testing is a long and slow process that spans chapters
33
- 3 through 10 in railstutorial.org. The GenericApp Ruby gem allows you to create such a site in seconds instead of
36
+ Creating a basic generic web site with user authentication and testing is a long and slow process that spans chapters
37
+ 3 through 10 in railstutorial.org. The GenericApp Ruby gem allows you to create such a site in minutes instead of
34
38
  hours. This is valuable for any project and essential for events like Startup Weekend and 24-hour website
35
39
  challenges.
36
40
  <br><br>
37
- The GenericApp gem copies the railstutorial.org Sample App for use as a template for starting a new project.
38
- (Note that the microposts and followers features are not included, because they are specific to the Sample App.)
39
- Starting a Rails app completely from scratch (by using the "rails new" command) requires manually installing and
40
- configuring MiniTest, Guard, Twitter bootstrap, the user model, user sign-ups, user login/logout, user
41
- authorization, administrative users, account activations, and password resets. People are often tempted to "save
42
- time" by omitting testing. Using the GenericApp gem allows you to have all of the essential basic elements of a
43
- generic app as soon as you start it. It's a shortcut that actually complies with best practices.
41
+ The GenericApp gem copies the GenericApp Template (https://github.com/jhsu802701/generic_app_template) for use as a template for starting a new project. Starting a Rails app completely from scratch (by using the "rails new" command) requires manually installing and configuring MiniTest, Guard, Twitter bootstrap, the user model, user sign-ups, user login/logout, user authorization, administrative users, account activations, and password resets. People are often tempted to "save time" by omitting testing. Using the GenericApp gem allows you to have all of the essential basic elements of a generic app as soon as you start it. It's a shortcut that actually complies with best practices.
44
42
  <br><br>
45
- The original Rails Tutorial Sample App provides the following features:
46
-
43
+ Features provided by GenericApp include:
47
44
  1. Static pages
48
- 2. Tests
49
- 3. Automated tests through Guard
45
+ 2. A comprehensive suite of tests, including Capybara integration tests
46
+ 3. Guard for automated testing
50
47
  4. Twitter bootstrap
51
- 5. Databases: SQLite3 for development and PostgreSQL for production
48
+ 5. Databases: SQLite3 for development and PostgreSQL for production PLUS a script that automates the process of setting PostgreSQL parameters AND excluding your username and password from the Git repository
52
49
  6. Ready for Heroku deployment
53
- 7. User functionality: includes hashed passwords, administrative users, account activations, and password resets
54
-
55
- This generic Rails app provides the above features PLUS these additional
56
- features:
57
-
58
- 1. Bash scripts in the root directory that allow you to perform routine tasks in only one step. (These scripts are likely to be useful in Rails apps that were not created with this generic_app Ruby gem.)
59
- 2. Recommendations that the user make use of password management software to generate and store secure passwords
60
- 3. Outlines of the MVC, test suite, and database seeding process in the notes folder
61
- 4. Guard automatically runs tests upon startup.
62
- 5. If you choose PostgreSQL (instead of SQLite) as your development environment database, the parameters are automatically set on your machine AND in the app for you, and the username and password are EXCLUDED from the source code saved with Git.
50
+ 7. The devise gem for providing user and admin authentication
51
+ 8. Bash scripts in the root directory that allow you to perform routine tasks in only one step.
52
+ 9. Recommendations that the user make use of password management software to generate and store secure passwords
53
+ 10. Outlines of the MVC, test suite, and database seeding process in the notes folder
54
+ 11. Guard automatically runs tests upon startup.
55
+ 12. Tools for checking code quality
56
+ 13. Code Climate test reporting and badges for the README page
63
57
 
64
58
  ## Development
65
59
 
66
60
  ### Testing GenericApp
67
61
  Download this GitHub repository, cd into the source code, and enter the command "sh gem_test.sh". The screen output is saved to the log files in the log directory. If all goes well, every test is completed with 0 or 31m0 failures and 0 errors.
68
62
 
69
- ### Special Note on Figaro
70
- The Figaro gem is used for this gem AND any PostgreSQL projects created. In the interest of avoiding confusion, the same versions of Figaro are specified in the GenericApp gemspec AND in the Gemfile of PostgreSQL-based projects created with this gem.
71
-
72
63
  ## Contributing
73
64
 
74
65
  1. Fork it ( https://github.com/jhsu802701/generic_app/fork )
data/bin/generic_app CHANGED
@@ -11,108 +11,34 @@ def get_input(default_value)
11
11
  end
12
12
  end
13
13
 
14
- puts "***********************"
15
- puts "Welcome to Generic App!"
14
+ puts '***********************'
15
+ puts 'Welcome to Generic App!'
16
16
  puts
17
- db_type = ""
18
17
 
19
- until db_type == "S" or db_type == "s" or db_type == "P" or db_type == "p" do
20
- puts "Which database do you wish to use, SQLite or PostgreSQL?"
21
- puts "Enter 'S' or 's' to select SQLite."
22
- puts "Enter 'P' or 'p' to select PostgreSQL."
23
- db_type = gets.chomp
24
- end
25
-
26
- default_subdir = "tmp9"
18
+ default_subdir = 'tmp9'
27
19
  puts
28
20
  puts "DEFAULT VALUE: #{default_subdir}"
29
- puts "Enter the directory name you wish to use for your generic app:"
21
+ puts 'Enter the directory name you wish to use for your generic app:'
30
22
  subdir_name = get_input(default_subdir)
31
23
  puts "You chose '#{subdir_name}'."
32
24
  puts
33
25
 
34
- n = Time.now.to_i
26
+ default_email = 'please-change-me-at-config-initializers-devise@example.com'
27
+ puts "DEFAULT VALUE: #{default_email}"
28
+ puts "Enter the email address you wish to use for your generic app's mailer:"
29
+ email = get_input(default_email)
35
30
 
36
- if db_type == "P" or db_type == "p"
37
- # self.pg (subdir_name, db_rootname_x, var_store_username, var_store_password, username_x, password_x)
38
- puts
39
- puts "You chose PostgreSQL."
40
- puts
41
-
42
- default_root = "db_#{subdir_name}_#{n}"
43
- puts "DEFAULT database names: "
44
- puts "Root: #{default_root}"
45
- puts "Development: #{default_root}_dev"
46
- puts "Testing: #{default_root}_test"
47
- puts "Production: #{default_root}_pro"
48
- puts
49
-
50
- puts "Enter the root name of your database:"
51
- db_rootname_x = get_input(default_root)
52
- puts
53
- puts "The database names you selected are:"
54
- puts "Root: #{db_rootname_x}"
55
- puts "Development: #{db_rootname_x}_dev"
56
- puts "Testing: #{db_rootname_x}_test"
57
- puts "Production: #{db_rootname_x}_pro"
58
- puts
59
-
60
- default_var_store_username = "var_user_#{subdir_name}_#{n}"
61
- puts "DEFAULT environmental variable for storing your username: #{default_var_store_username}"
62
- puts "Enter the name you wish to use for the ENVIRONMENTAL VARIABLE that stores your username:"
63
- var_store_username = get_input(default_var_store_username)
64
- puts
65
- puts "Environmental variable for storing your username: #{var_store_username}"
66
- puts
67
-
68
- default_var_store_password = "var_password_#{subdir_name}_#{n}"
69
- puts "DEFAULT environmental variable for your password: #{default_var_store_password}"
70
- puts "Enter the name you wish to use for the ENVIRONMENTAL VARIABLE that stores your password:"
71
- var_store_password = get_input(default_var_store_password)
72
- puts
73
- puts "Environmental variable for storing your password: #{var_store_password}"
74
- puts
75
-
76
- default_username = "user_#{subdir_name}_#{n}"
77
- puts "DEFAULT username: #{default_username}"
78
- puts "Enter the username you wish to use:"
79
- username_x = get_input(default_username)
80
- puts
81
- puts "Your username: #{username_x}"
82
- puts
83
-
84
- default_password = "long_way_stinks"
85
- puts "NOTE: It is recommended that you use the program KeePassX (http://www.keepassx.org/) to generate secure passwords AND store them."
86
- puts
87
- puts "DEFAULT password: #{default_password}"
88
- puts "Enter the password you wish to use:"
89
- password_x = get_input(default_password)
90
- puts
91
- puts "Your password: #{password_x}"
92
- puts
93
- GenericApp.pg(subdir_name, db_rootname_x, var_store_username, var_store_password, username_x, password_x)
94
-
95
- else
96
- puts "You chose SQLite."
97
- GenericApp.sq(subdir_name)
98
- end
31
+ GenericApp.create_new(subdir_name, email)
99
32
 
100
- puts "*********************************************"
33
+ puts '*********************************************'
101
34
  puts "BEGIN TESTING THE #{subdir_name} RAILS APP"
102
- system("cd #{subdir_name} && sh test.sh")
35
+ system("cd #{subdir_name} && sh test_app.sh")
103
36
  puts "FINISHED TESTING THE #{subdir_name} RAILS APP"
104
- puts "*********************************************"
105
- if db_type == "P" or db_type == "p"
106
- puts "DATABASE PARAMETERS:"
107
- puts "The database names you selected are:"
108
- puts "Root: #{db_rootname_x}"
109
- puts "Development: #{db_rootname_x}_dev"
110
- puts "Testing: #{db_rootname_x}_test"
111
- puts "Production: #{db_rootname_x}_pro"
112
- puts
113
- puts "Environmental variable for storing your username: #{var_store_username}"
114
- puts "Environmental variable for storing your password: #{var_store_password}"
115
- puts "Your username: #{username_x}"
116
- puts "Your password: #{password_x}"
117
- puts
118
- end
37
+ puts '*********************************************'
38
+
39
+ puts "Your new Rails app has been created at #{ENV['PWD']}/#{subdir_name} ."
40
+ puts 'It is currently configured to use the SQLite database in the'
41
+ puts 'development environment.'
42
+ puts 'To set up the PostgreSQL database, enter the'
43
+ puts "#{ENV['PWD']}/#{subdir_name} directory and enter the command"
44
+ puts 'sh setup-pg.sh .'
data/bin/generic_app_add CHANGED
@@ -3,30 +3,33 @@
3
3
  require 'generic_app'
4
4
 
5
5
  valid_folder = false
6
- dir_app = ""
6
+ dir_app = ''
7
7
 
8
- while valid_folder = false or dir_app == "" do
9
- puts "*************************************************"
10
- puts "Adding Generic App features to a pre-existing app"
8
+ while valid_folder = false or dir_app == '' do
9
+ puts '*************************************************'
10
+ puts 'Adding Generic App features to a pre-existing app'
11
11
  puts
12
12
  puts "Present working directory: #{Dir.pwd}"
13
13
  puts
14
- system ("ls")
14
+ system ('ls')
15
15
  puts
16
- puts "Enter the name of the directory in which you wish to add the features of Generic App:"
16
+ puts 'Enter the name of the directory in which you wish to add the features of Generic App:'
17
17
  dir_app = gets.chomp
18
18
  begin
19
- GenericApp.add_scripts (dir_app)
20
- GenericApp.update_gitignore (dir_app)
19
+ GenericApp.add (dir_app)
21
20
  valid_folder = true
22
21
  rescue
23
22
  end
24
23
  end
25
24
 
26
- puts "*********************************************"
27
- puts "BEGIN TESTING THE PRE-EXISTING RAILS APP"
28
- system("cd #{dir_app} && sh test.sh")
29
- puts "FINISHED TESTING THE PRE-EXISTING RAILS APP"
30
- puts "*********************************************"
31
- puts "The test.sh script is designed around the railstutorial.org Sample App."
32
- puts "If any tests failed, or if the tests failed to run, then you likely need to revise the test.sh script."
25
+ puts '***********************************'
26
+ puts 'Please enter the following command'
27
+ puts 'to enter the app:'
28
+ puts "cd #{dir_app}"
29
+ puts
30
+ puts 'Please note that certain scripts (like test_app.sh and seed.sh)'
31
+ puts 'may need to be revised for this legacy app.'
32
+ puts
33
+ puts 'If this legacy app uses the PostgreSQL database, run the '
34
+ puts 'setup-pg.sh script to set up the database and its user.'
35
+ puts
data/gem_install.sh CHANGED
@@ -1,9 +1,12 @@
1
1
  #!/bin/bash
2
2
 
3
- gem uninstall generic_app
3
+ gem cleanup generic_app
4
4
  bin/setup
5
- echo "****************************"
6
- echo "BEGIN INSTALLING generic_app"
7
- rake install
5
+ echo '------------------------'
6
+ echo 'Building generic_app gem'
7
+ gem build generic_app.gemspec
8
+ echo '------------------------'
9
+ echo 'Installing generic_app gem'
10
+ gem install generic_app*.gem
8
11
  echo "FINISHED INSTALLING generic_app"
9
12
  echo "*******************************"
data/gem_test.sh CHANGED
@@ -2,49 +2,42 @@
2
2
 
3
3
  gem uninstall generic_app
4
4
  DIR_GENERIC_APP=$PWD
5
+ DIR_PARENT="${PWD%/*}"
5
6
  mkdir -p log
6
7
 
7
8
  echo "**************"
8
9
  echo "bundle install"
9
10
  bin/setup >/dev/null
11
+
10
12
  echo "*************************"
11
13
  echo "BEGIN TESTING generic_app"
12
14
  rake 2>&1 | tee $DIR_GENERIC_APP/log/generic_app.txt
13
15
  echo "FINISHED TESTING generic_app"
14
16
  echo "****************************"
15
17
 
16
- echo "********************************"
17
- echo "BEGIN TESTING THE tmp1 RAILS APP"
18
- cd tmp1 && sh test.sh 2>&1 | tee $DIR_GENERIC_APP/log/tmp1.txt
19
- echo "FINISHED TESTING THE tmp1 RAILS APP"
20
- echo "***********************************"
21
-
22
- echo "********************************"
23
- echo "BEGIN TESTING THE tmp2 RAILS APP"
24
- cd ..
25
- cd tmp2 && sh test.sh 2>&1 | tee $DIR_GENERIC_APP/log/tmp2.txt
26
- echo "FINISHED TESTING THE tmp2 RAILS APP"
27
- echo "***********************************"
28
-
29
- echo "********************************"
30
- echo "BEGIN TESTING THE tmp3 RAILS APP"
31
- cd ..
32
- cd tmp3 && sh test.sh 2>&1 | tee $DIR_GENERIC_APP/log/tmp3.txt
33
- echo "FINISHED TESTING THE tmp3 RAILS APP"
34
- echo "***********************************"
35
-
36
- echo "********************************"
37
- echo "BEGIN TESTING THE tmp4 RAILS APP"
38
- cd ..
39
- cd tmp4 && sh test.sh 2>&1 | tee $DIR_GENERIC_APP/log/tmp4.txt
40
- echo "FINISHED TESTING THE tmp4 RAILS APP"
41
- echo "***********************************"
42
-
43
- echo "The log of the generic_app test is at $DIR_GENERIC_APP/log/generic_app.txt."
44
- echo "The log of the tmp1 Rails app test is at $DIR_GENERIC_APP/log/tmp1.txt."
45
- echo "The log of the tmp2 Rails app test is at $DIR_GENERIC_APP/log/tmp2.txt."
46
- echo "The log of the tmp3 Rails app test is at $DIR_GENERIC_APP/log/tmp3.txt."
47
- echo "The log of the tmp4 Rails app test is at $DIR_GENERIC_APP/log/tmp4.txt."
18
+ echo '************'
19
+ echo 'BEGIN TEST 1'
20
+ echo 'Creating new Rails app'
21
+
22
+ cd $DIR_PARENT/tmp1 && sh test_app.sh 2>&1 | tee $DIR_GENERIC_APP/log/tmp1.txt
23
+ echo 'FINISHED TEST 1'
24
+ echo '***************'
25
+
26
+ echo '************'
27
+ echo 'BEGIN TEST 2'
28
+ echo 'Adding Generic App features to legacy Rails app'
29
+
30
+ cd $DIR_PARENT/tmp2 && sh test_app.sh 2>&1 | tee $DIR_GENERIC_APP/log/tmp2.txt
31
+ echo 'FINISHED TEST 2'
32
+ echo '***************'
33
+
34
+
35
+
36
+ echo
37
+ echo '***********************************'
38
+ echo 'The locations of the test logs are:'
39
+ echo "TEST 1 (new app): $DIR_GENERIC_APP/tmp1.txt"
40
+ echo "TEST 2 (legacy app): $DIR_GENERIC_APP/tmp2.txt"
48
41
  echo
49
42
  echo "If all went well, the results at the end of each test show 0 or 31m0 failures and 0 errors."
50
43
  echo
data/generic_app.gemspec CHANGED
@@ -23,5 +23,4 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_runtime_dependency "string_in_file"
25
25
  spec.add_runtime_dependency "line_containing"
26
- spec.add_runtime_dependency "figaro", "1.1.0"
27
26
  end
@@ -1,3 +1,3 @@
1
1
  module GenericApp
2
- VERSION = "0.1.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/generic_app.rb CHANGED
@@ -5,58 +5,33 @@ require "string_in_file"
5
5
  require "line_containing"
6
6
 
7
7
  ENV['DIR_MAIN'] = File.expand_path("../../", __FILE__)
8
+ ENV['DIR_PARENT'] = File.expand_path("../../../", __FILE__)
8
9
 
9
10
  module GenericApp
10
-
11
11
  # Create app, stick with SQLite database in development
12
- def self.sq (subdir_name)
12
+ def self.create_new (subdir_name, email)
13
13
  self.git_clone (subdir_name)
14
- self.guard_file (subdir_name)
15
- self.app_views_password (subdir_name)
16
- self.guard_file (subdir_name)
17
- self.add_scripts (subdir_name) # Also used in the add-on procedure
18
- self.add_notes (subdir_name)
19
- self.add_readme (subdir_name)
20
- self.update_gitignore (subdir_name) # Also used in the add-on procedure
14
+ self.email_update(subdir_name, email)
21
15
  self.git_init (subdir_name)
22
16
  end
23
-
17
+
24
18
  def self.git_clone (subdir_name)
25
- puts "*************************************************"
26
- puts "Downloading the Sample App from railstutorial.org"
19
+ puts "------------------------------------"
20
+ puts "Downloading the Generic App Template"
27
21
  t1 = Thread.new {
28
- system("git clone https://github.com/mhartl/sample_app_3rd_edition.git #{subdir_name}")
29
- system("cd #{subdir_name} && git checkout remotes/origin/account-activation-password-reset")
22
+ system("git clone https://github.com/jhsu802701/generic_app_template.git #{subdir_name}")
30
23
  }
31
24
  t1.join
32
25
  end
33
26
 
34
- def self.guard_file (subdir_name)
35
- puts "*************************************************************"
36
- puts "Setting the Guardfile to automatically run tests upon startup"
37
- str_guard_orig = "all_on_start: false"
38
- str_guard_new = "all_on_start: true"
39
- StringInFile.replace(str_guard_orig, str_guard_new, "#{subdir_name}/Guardfile")
40
- end
41
-
42
- def self.app_views_password (subdir_name)
43
- puts "*********************************************************************************"
44
- puts "Advising users to use a password management program to create and store passwords"
45
- str1 = "</h1>"
46
- str2a = "</h1>"
47
- str2b = "\nUsing the same password for all of your accounts is risky."
48
- str2b += "\nLimiting yourself to passwords that you can easily remember is risky."
49
- str2b += "\nYou should use a password management program like <a href='http://www.keepassx.org/'>KeePassX</a>"
50
- str2b += "\nto create much better passwords AND store them in encrypted form.<br>"
51
- str2 = str2a + str2b
52
- StringInFile.replace(str1, str2, "#{subdir_name}/app/views/users/new.html.erb")
53
- StringInFile.replace(str1, str2, "#{subdir_name}/app/views/users/edit.html.erb")
54
- StringInFile.replace(str1, str2, "#{subdir_name}/app/views/password_resets/new.html.erb")
55
- StringInFile.replace(str1, str2, "#{subdir_name}/app/views/password_resets/edit.html.erb")
27
+ def self.email_update (subdir_name, email)
28
+ email_orig = 'please-change-me-at-config-initializers-devise@example.com'
29
+ path_of_email = "#{subdir_name}/config/initializers/devise.rb"
30
+ StringInFile.replace(email_orig, email, path_of_email)
56
31
  end
57
-
32
+
58
33
  def self.git_init (subdir_name)
59
- puts "****************"
34
+ puts "----------------"
60
35
  puts "Initializing Git"
61
36
  t1 = Thread.new {
62
37
  $stdout = File.new( '/dev/null', 'w' )
@@ -68,29 +43,14 @@ module GenericApp
68
43
  }
69
44
  t1.join
70
45
  end
71
-
72
- def self.add_scripts (subdir_name)
73
- puts "*******************"
74
- puts "Adding Bash scripts"
75
- system("cp -r #{ENV['DIR_MAIN']}/to_add/*.sh #{subdir_name}")
76
- system("cd #{subdir_name} && sh list_files.sh")
77
- end
78
-
79
- def self.add_notes (subdir_name)
80
- puts "*****************************"
81
- puts "Adding notes on MVC structure"
82
- system("mkdir -p #{subdir_name}/notes")
83
- system("cp -r #{ENV['DIR_MAIN']}/to_add/notes/* #{subdir_name}/notes")
84
- end
85
-
86
- def self.add_readme (subdir_name)
87
- puts "*****************************"
88
- puts "Adding README"
89
- system("cp -r #{ENV['DIR_MAIN']}/to_add/README.md #{subdir_name}")
46
+
47
+ def self.add (subdir_name)
48
+ self.update_gitignore (subdir_name)
49
+ self.copy_scripts (subdir_name)
90
50
  end
91
-
51
+
92
52
  def self.update_gitignore (subdir_name)
93
- puts "*******************"
53
+ puts "-------------------"
94
54
  puts "Updating .gitignore"
95
55
  if StringInFile.present("tmp*","#{subdir_name}/.gitignore") == false
96
56
  command = 'echo "\ntmp*" >> '
@@ -103,117 +63,15 @@ module GenericApp
103
63
  system(command)
104
64
  end
105
65
  end
106
-
107
- # Create app, use PostgreSQL instead of SQLite
108
- # NOTE: Three databases are used: development, testing, and production.
109
- # NOTE: Each database has the same username and password.
110
-
111
- # INPUT PARAMETERS:
112
- # Name of directory containing the app
113
- # Database root name
114
- # Name of environmental variable used to store the username
115
- # Name of environmental variable used to store the password
116
- # Username
117
- # Password
118
66
 
119
- def self.pg (subdir_name, db_rootname_x, var_store_username, var_store_password, username_x, password_x)
120
- self.sq (subdir_name)
121
- self.pg_gemfile (subdir_name)
122
- self.pg_remove_sqlite (subdir_name)
123
- t1 = Thread.new {
124
- self.set_pg_params(subdir_name, db_rootname_x, var_store_username, var_store_password, username_x, password_x)
125
- }
126
- t1.join
127
- self.git_init (subdir_name)
128
- end
129
-
130
- def self.pg_gemfile (subdir_name)
131
- puts "**************************************************************************"
132
- puts "Updating the Gemfile (PostgreSQL for development, testing, and production)"
133
- LineContaining.delete("sqlite", "#{subdir_name}/Gemfile")
134
- LineContaining.delete("gem 'pg'", "#{subdir_name}/Gemfile")
135
- open("#{subdir_name}/Gemfile", 'a') {|f|
136
- f << "\n\ngem 'pg'\n"
137
- f << "gem 'figaro', '1.1.0'\n"
138
- }
139
- end
140
-
141
- def self.pg_remove_sqlite (subdir_name)
142
- system("rm #{subdir_name}/db/*.sqlite")
67
+ def self.copy_scripts (subdir_name)
68
+ puts "----------------------------------------------"
69
+ puts "Adding scripts and config/database-pg.yml file"
70
+ dir_template = "#{ENV['DIR_PARENT']}/high_speed_rails_clobbers_not_exactly"
71
+ self.git_clone (dir_template)
72
+ system("cp -r #{dir_template}/*.sh #{subdir_name}")
73
+ system("cp -r #{dir_template}/*.rb #{subdir_name}")
74
+ system("cp -r #{dir_template}/config/database-pg.yml #{subdir_name}/config")
75
+ system("rm -rf #{dir_template}")
143
76
  end
144
-
145
- def self.set_pg_params (subdir_name, db_rootname_x, var_store_username, var_store_password, username_x, password_x)
146
- system("cp -r #{ENV['DIR_MAIN']}/to_add_pg/* #{subdir_name}")
147
- puts "*********************************************"
148
- puts "Setting up the PostgreSQL database parameters"
149
- # NOTE: These environmental variables are temporary and only used here.
150
- ENV['APP_DB_NAME_DEV'] = "#{db_rootname_x}_dev"
151
- ENV['APP_DB_NAME_TEST'] = "#{db_rootname_x}_test"
152
- ENV['APP_DB_NAME_PRO'] = "#{db_rootname_x}_pro"
153
- ENV['APP_DB_USER'] = username_x
154
- ENV['APP_DB_PASS'] = password_x
155
- system(%q{sudo -u postgres psql -c"CREATE ROLE $APP_DB_USER WITH CREATEDB LOGIN PASSWORD '$APP_DB_PASS';"})
156
-
157
- # Development database
158
- system(%q{sudo -u postgres psql -c"CREATE DATABASE $APP_DB_NAME_DEV WITH OWNER=$APP_DB_USER;"})
159
- system("wait")
160
-
161
- # Testing database
162
- system(%q{sudo -u postgres psql -c"CREATE DATABASE $APP_DB_NAME_TEST WITH OWNER=$APP_DB_USER;"})
163
- system("wait")
164
-
165
- # Production database
166
- system(%q{sudo -u postgres psql -c"CREATE DATABASE $APP_DB_NAME_PRO WITH OWNER=$APP_DB_USER;"})
167
- system("wait")
168
-
169
- puts "****************************************"
170
- puts "rm #{subdir_name}/config/application.yml"
171
- system ("rm #{subdir_name}/config/application.yml")
172
-
173
- puts "**************************************************"
174
- puts "Using Figaro to create initial configuration files"
175
- system("cd #{subdir_name} && figaro install")
176
-
177
- puts
178
- puts "*********************************"
179
- puts "Setting up config/application.yml"
180
- open("#{subdir_name}/config/application.yml", 'a') { |f|
181
- f << "\n\n"
182
- f << 'VAR_STORE_USERNAME: "USERNAME123"'
183
- f << "\n"
184
- f << 'VAR_STORE_PASSWORD: "PASSWORD123"'
185
- }
186
- StringInFile.replace("VAR_STORE_USERNAME", var_store_username, "#{subdir_name}/config/application.yml")
187
- StringInFile.replace("USERNAME123", username_x, "#{subdir_name}/config/application.yml")
188
- StringInFile.replace("VAR_STORE_PASSWORD", var_store_password, "#{subdir_name}/config/application.yml")
189
- StringInFile.replace("PASSWORD123", password_x, "#{subdir_name}/config/application.yml")
190
- puts
191
- puts "******************************"
192
- puts "Setting up config/database.yml"
193
- system("cp -r #{ENV['DIR_MAIN']}/to_add_pg/* #{subdir_name}")
194
- StringInFile.replace("VAR_STORE_USERNAME", var_store_username, "#{subdir_name}/config/database.yml")
195
- StringInFile.replace("VAR_STORE_PASSWORD", var_store_password, "#{subdir_name}/config/database.yml")
196
- StringInFile.replace("DB_NAME_DEV", ENV['APP_DB_NAME_DEV'], "#{subdir_name}/config/database.yml")
197
- StringInFile.replace("DB_NAME_TEST", ENV['APP_DB_NAME_TEST'], "#{subdir_name}/config/database.yml")
198
- StringInFile.replace("DB_NAME_PRO", ENV['APP_DB_NAME_PRO'], "#{subdir_name}/config/database.yml")
199
- puts
200
- puts "*************************************"
201
- puts "POSTGRESQL PUBLIC DATABASE PARAMETERS"
202
- puts "This information is stored in the config/database.yml file"
203
- puts "Database Name (development): #{ENV['APP_DB_NAME_DEV']}"
204
- puts "Database Name (testing): #{ENV['APP_DB_NAME_TEST']}"
205
- puts "Database Name (production): #{ENV['APP_DB_NAME_PRO']}"
206
- puts "Name of Environmental Variable Containing The Username: #{var_store_username}"
207
- puts "Name of Environmental Variable Containing the Password: #{var_store_password}"
208
- puts
209
- puts "**************************************"
210
- puts "POSTGRESQL PRIVATE DATABASE PARAMETERS"
211
- puts "This information is stored in the config/application.yml file."
212
- puts "The config/application.yml file is ignored by Git, which keeps it private."
213
- puts "Be sure you have this information saved in KeePassX."
214
- puts "Username: #{username_x}"
215
- puts "Password: #{password_x}"
216
-
217
- end
218
-
219
77
  end