generic_app 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/README.md +15 -14
- data/Rakefile +0 -2
- data/bin/generic_app +110 -4
- data/bin/generic_app_add +32 -0
- data/bin/setup +7 -0
- data/gem_install.sh +9 -0
- data/gem_test.sh +50 -0
- data/generic_app.gemspec +2 -1
- data/lib/generic_app/version.rb +2 -2
- data/lib/generic_app.rb +203 -46
- data/spec/lib/1_sq_spec.rb +62 -0
- data/spec/lib/2_pg_spec.rb +23 -0
- data/spec/lib/3_pg_spec.rb +33 -0
- data/spec/lib/4_addon_spec.rb +43 -0
- data/to_add/README.md +17 -42
- data/to_add/list_files.sh +32 -15
- data/to_add/notes/0-README.md +9 -0
- data/to_add/notes/2-db.txt +77 -0
- data/to_add/notes/3-db-summary.txt +19 -0
- data/to_add/notes/mvc-account_activations.txt +10 -0
- data/to_add/notes/mvc-application.txt +7 -0
- data/to_add/notes/mvc-layouts.txt +9 -0
- data/to_add/notes/mvc-password_resets.txt +25 -0
- data/to_add/notes/mvc-sessions.txt +27 -0
- data/to_add/notes/mvc-shared_views.txt +4 -0
- data/to_add/notes/mvc-static.txt +22 -0
- data/to_add/notes/mvc-users.txt +96 -0
- data/to_add/notes/tests.txt +2 -59
- data/to_add/{setup.sh → test.sh} +1 -0
- data/to_add_pg/config/database.yml +26 -0
- metadata +45 -10
- data/setup.sh +0 -5
- data/spec/lib/generic_app_spec.rb +0 -45
- data/to_add/notes/mvc_by_object.txt +0 -160
- data/to_add/notes/seed.txt +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2869a56b7b1f7a2c19145e9e8ed38d24d4684c1e
|
4
|
+
data.tar.gz: 002831a504c9195d6f3751e1ee9e384f1a3eb80f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 914826899f90b1c63c3c65feb93e9e6a09277f77266b47d407feab3097fbc7b4c4500ae637fa38327acc82753ef560682565a4887beaa04757354e2b8bfed7b9
|
7
|
+
data.tar.gz: 305f11a464b078fa7b0318cdeefdfa317e4250a027e16926ee3871d5f4f8bb8119d150cf9e562af083dd7720f4f70d2ea32d0cd755c9324e178203c3061eaa43
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# GenericApp
|
2
2
|
|
3
|
+
## Prerequisites
|
4
|
+
|
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 ).
|
6
|
+
|
3
7
|
## Installation
|
4
8
|
|
5
9
|
Install it yourself with the command:
|
@@ -8,10 +12,11 @@ Install it yourself with the command:
|
|
8
12
|
|
9
13
|
## Usage
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
asked to
|
14
|
-
|
15
|
+
### Creating A Rails App
|
16
|
+
|
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.
|
18
|
+
<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.
|
15
20
|
|
16
21
|
## What's the point?
|
17
22
|
|
@@ -21,7 +26,7 @@ can spend more of your time on the more advanced features and capabilities that
|
|
21
26
|
app. Modifying a generic app takes far less time than creating an app completely from scratch.
|
22
27
|
<br><br>
|
23
28
|
Creating a basic generic web site with user capability and testing is a long and slow process that spans chapters
|
24
|
-
3 through 10
|
29
|
+
3 through 10 in railstutorial.org. The GenericApp Ruby gem allows you to create such a site in seconds instead of
|
25
30
|
hours. This is valuable for any project and essential for events like Startup Weekend and 24-hour website
|
26
31
|
challenges.
|
27
32
|
<br><br>
|
@@ -41,20 +46,16 @@ The original Rails Tutorial Sample App provides the following features:
|
|
41
46
|
4. Twitter bootstrap
|
42
47
|
5. Databases: SQLite3 for development and PostgreSQL for production
|
43
48
|
6. Ready for Heroku deployment
|
44
|
-
7. User functionality: includes hashed passwords, administrative users,
|
45
|
-
account activations, and password resets
|
49
|
+
7. User functionality: includes hashed passwords, administrative users, account activations, and password resets
|
46
50
|
|
47
51
|
This generic Rails app provides the above features PLUS these additional
|
48
52
|
features:
|
49
53
|
|
50
|
-
1. Bash scripts in the root directory that allow you to perform routine
|
51
|
-
|
52
|
-
|
53
|
-
2. Recommendations that the user make use of password management software
|
54
|
-
to generate and store secure passwords
|
55
|
-
3. Outlines of the MVC, test suite, and database seeding process in the
|
56
|
-
notes folder
|
54
|
+
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.)
|
55
|
+
2. Recommendations that the user make use of password management software to generate and store secure passwords
|
56
|
+
3. Outlines of the MVC, test suite, and database seeding process in the notes folder
|
57
57
|
4. Guard automatically runs tests upon startup.
|
58
|
+
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.
|
58
59
|
|
59
60
|
## Contributing
|
60
61
|
|
data/Rakefile
CHANGED
data/bin/generic_app
CHANGED
@@ -2,11 +2,117 @@
|
|
2
2
|
|
3
3
|
require 'generic_app'
|
4
4
|
|
5
|
-
|
5
|
+
def get_input(default_value)
|
6
|
+
value_input = gets.chomp
|
7
|
+
if value_input == ""
|
8
|
+
return default_value
|
9
|
+
else
|
10
|
+
return value_input
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
6
14
|
puts "***********************"
|
7
15
|
puts "Welcome to Generic App!"
|
8
16
|
puts
|
9
|
-
|
17
|
+
db_type = ""
|
18
|
+
|
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"
|
27
|
+
puts
|
28
|
+
puts "DEFAULT VALUE: #{default_subdir}"
|
10
29
|
puts "Enter the directory name you wish to use for your generic app:"
|
11
|
-
subdir_name =
|
12
|
-
|
30
|
+
subdir_name = get_input(default_subdir)
|
31
|
+
puts "You chose '#{subdir_name}'."
|
32
|
+
puts
|
33
|
+
|
34
|
+
n = Time.now.to_i
|
35
|
+
|
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
|
99
|
+
|
100
|
+
puts "*********************************************"
|
101
|
+
puts "BEGIN TESTING THE #{subdir_name} RAILS APP"
|
102
|
+
system("cd #{subdir_name} && sh test.sh")
|
103
|
+
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
|
data/bin/generic_app_add
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'generic_app'
|
4
|
+
|
5
|
+
valid_folder = false
|
6
|
+
dir_app = ""
|
7
|
+
|
8
|
+
while valid_folder = false or dir_app == "" do
|
9
|
+
puts "*************************************************"
|
10
|
+
puts "Adding Generic App features to a pre-existing app"
|
11
|
+
puts
|
12
|
+
puts "Present working directory: #{Dir.pwd}"
|
13
|
+
puts
|
14
|
+
system ("ls")
|
15
|
+
puts
|
16
|
+
puts "Enter the name of the directory in which you wish to add the features of Generic App:"
|
17
|
+
dir_app = gets.chomp
|
18
|
+
begin
|
19
|
+
GenericApp.add_scripts (dir_app)
|
20
|
+
GenericApp.update_gitignore (dir_app)
|
21
|
+
valid_folder = true
|
22
|
+
rescue
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
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."
|
data/bin/setup
ADDED
data/gem_install.sh
ADDED
data/gem_test.sh
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
gem uninstall generic_app
|
4
|
+
DIR_GENERIC_APP=$PWD
|
5
|
+
mkdir -p log
|
6
|
+
|
7
|
+
echo "**************"
|
8
|
+
echo "bundle install"
|
9
|
+
bin/setup >/dev/null
|
10
|
+
echo "*************************"
|
11
|
+
echo "BEGIN TESTING generic_app"
|
12
|
+
rake 2>&1 | tee $DIR_GENERIC_APP/log/generic_app.txt
|
13
|
+
echo "FINISHED TESTING generic_app"
|
14
|
+
echo "****************************"
|
15
|
+
|
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."
|
48
|
+
echo
|
49
|
+
echo "If all went well, the results at the end of each test show 0 or 31m0 failures and 0 errors."
|
50
|
+
echo
|
data/generic_app.gemspec
CHANGED
@@ -22,5 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'rspec'
|
23
23
|
|
24
24
|
spec.add_runtime_dependency "string_in_file"
|
25
|
-
spec.add_runtime_dependency "
|
25
|
+
spec.add_runtime_dependency "line_containing"
|
26
|
+
spec.add_runtime_dependency "figaro"
|
26
27
|
end
|
data/lib/generic_app/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0
|
1
|
+
module GenericApp
|
2
|
+
VERSION = "0.1.0"
|
3
3
|
end
|
data/lib/generic_app.rb
CHANGED
@@ -2,61 +2,218 @@
|
|
2
2
|
|
3
3
|
require "generic_app/version"
|
4
4
|
require "string_in_file"
|
5
|
+
require "line_containing"
|
5
6
|
|
6
|
-
|
7
|
+
ENV['DIR_MAIN'] = File.expand_path("../../", __FILE__)
|
7
8
|
|
8
|
-
|
9
|
+
module GenericApp
|
10
|
+
|
11
|
+
# Create app, stick with SQLite database in development
|
12
|
+
def self.sq (subdir_name)
|
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
|
21
|
+
self.git_init (subdir_name)
|
9
22
|
end
|
10
|
-
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
t1 = Thread.new {
|
16
|
-
puts "*************************************************"
|
17
|
-
puts "Downloading the Sample App from railstutorial.org"
|
23
|
+
|
24
|
+
def self.git_clone (subdir_name)
|
25
|
+
puts "*************************************************"
|
26
|
+
puts "Downloading the Sample App from railstutorial.org"
|
27
|
+
t1 = Thread.new {
|
18
28
|
system("git clone https://github.com/mhartl/sample_app_3rd_edition.git #{subdir_name}")
|
19
29
|
system("cd #{subdir_name} && git checkout remotes/origin/account-activation-password-reset")
|
20
|
-
|
30
|
+
}
|
21
31
|
t1.join
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
32
|
+
end
|
33
|
+
|
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")
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.git_init (subdir_name)
|
59
|
+
puts "****************"
|
60
|
+
puts "Initializing Git"
|
61
|
+
t1 = Thread.new {
|
62
|
+
$stdout = File.new( '/dev/null', 'w' )
|
51
63
|
system("cd #{subdir_name} && rm -rf .git")
|
52
64
|
system("cd #{subdir_name} && git init")
|
53
|
-
}
|
65
|
+
system("cd #{subdir_name} && git add .")
|
66
|
+
system("cd #{subdir_name} && git commit -m 'Initial commit' >/dev/null")
|
67
|
+
$stdout = STDOUT
|
68
|
+
}
|
54
69
|
t1.join
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
puts "
|
59
|
-
puts "
|
70
|
+
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}")
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.update_gitignore (subdir_name)
|
93
|
+
puts "*******************"
|
94
|
+
puts "Updating .gitignore"
|
95
|
+
if StringInFile.present("tmp*","#{subdir_name}/.gitignore") == false
|
96
|
+
command = 'echo "\ntmp*" >> '
|
97
|
+
command += "#{subdir_name}/.gitignore"
|
98
|
+
system(command)
|
99
|
+
end
|
100
|
+
if StringInFile.present(".DS_Store","#{subdir_name}/.gitignore") == false
|
101
|
+
command = 'echo "\n.DS_Store" >> '
|
102
|
+
command += "#{subdir_name}/.gitignore"
|
103
|
+
system(command)
|
104
|
+
end
|
105
|
+
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
|
+
|
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'\n"
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.pg_remove_sqlite (subdir_name)
|
142
|
+
system("rm #{subdir_name}/db/*.sqlite")
|
143
|
+
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}"
|
60
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
|
+
|
61
217
|
end
|
218
|
+
|
62
219
|
end
|