rails_g_database 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +53 -6
- data/lib/generators/database/USAGE +35 -2
- data/lib/generators/database/database_generator.rb +1 -1
- data/lib/rails_g_database/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90fde1cd4c6959ca3b581503579c72b0b6ecc94c
|
4
|
+
data.tar.gz: c58648c338475da3841202dd8783e530a72f3b40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 863551e9a47bab45b075b1435785b9834ae038c1614b31317cc9838a7d742308ce7b5fba166d0e6b7402176cdfc9f9a1e423a67c0e26f0c5b400351a1ea42126
|
7
|
+
data.tar.gz: dfefa8a1c3bdd4c13484856e2ea69676b08b7333fd25defa7777d21736a30e1ee21dc0413ec91dfeb98d922cf05077d05573acdcc3a7b175a3b86c515c9a7c74
|
data/README.md
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
-
#
|
1
|
+
# Rails_g_database
|
2
2
|
|
3
|
-
Missing rails database generator
|
3
|
+
Missing rails database generator
|
4
|
+
I have found many and many tutorials how to use more than one DB with Ruby on Rails
|
5
|
+
finally I found [THIS](https://gist.github.com/redrick/7335229) gist forked from [rafaelchiti](https://github.com/rafaelchiti) that I believe is the right one and works for me the best :)
|
6
|
+
I am still using multiple appplications with more databases, so I thought this would ease my pain :)
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
7
|
-
Add this line to your application's Gemfile:
|
10
|
+
Add this line to your application's Gemfile (this way you get the most recent one):
|
8
11
|
|
9
|
-
gem '
|
12
|
+
gem 'rails_g_database'
|
10
13
|
|
11
14
|
And then execute:
|
12
15
|
|
@@ -14,11 +17,55 @@ And then execute:
|
|
14
17
|
|
15
18
|
Or install it yourself as:
|
16
19
|
|
17
|
-
$ gem install
|
20
|
+
$ gem install rails_g_database
|
18
21
|
|
19
22
|
## Usage
|
20
23
|
|
21
|
-
|
24
|
+
For now it lacks comments, but is functional for me :) here is the way to use it:
|
25
|
+
|
26
|
+
rails g database NAME adapter:adapter_name db:database_name login:username psswd:password host:host_name port:port_number
|
27
|
+
|
28
|
+
#### NAME
|
29
|
+
|
30
|
+
name your database here (also applies on directory names and so on ...)
|
31
|
+
|
32
|
+
|
33
|
+
#### adapter
|
34
|
+
|
35
|
+
for now it supports:
|
36
|
+
|
37
|
+
* MySQL (as 'mysql')
|
38
|
+
* PostgreSQL (as 'pg')
|
39
|
+
* SQLite (as 'sqlite')
|
40
|
+
|
41
|
+
#### db
|
42
|
+
|
43
|
+
you can change the name of your database othervise it falls back to the NAME of your db (in most cases leave blank :) )
|
44
|
+
|
45
|
+
#### login
|
46
|
+
|
47
|
+
except sqlite, you can specify your DB credentials (this one stand for username)
|
48
|
+
|
49
|
+
#### psswd
|
50
|
+
|
51
|
+
except sqlite, you can specify your DB credentials (this one stands for password)
|
52
|
+
|
53
|
+
#### host
|
54
|
+
|
55
|
+
except sqlite, you can specify your DB credentials (this one stands for host, in most cases localhost)
|
56
|
+
|
57
|
+
#### port
|
58
|
+
|
59
|
+
except sqlite, you can specify your DB credentials (this one stands for port, in case of postgresql 5432)
|
60
|
+
|
61
|
+
After generating all files we need, basically what you have to do is not to inherit from Activerecord::Base, but from newly created NAME::Base and there you go, you are working with another database :)
|
62
|
+
|
63
|
+
More info is on the way ...
|
64
|
+
|
65
|
+
|
66
|
+
## Thanks
|
67
|
+
|
68
|
+
To [rafaelchiti](https://github.com/rafaelchiti) for his [README](https://gist.github.com/rafaelchiti/5575309) that solved my problems
|
22
69
|
|
23
70
|
## Contributing
|
24
71
|
|
@@ -3,7 +3,40 @@ Description:
|
|
3
3
|
Just What We were missing
|
4
4
|
|
5
5
|
Example:
|
6
|
-
rails
|
6
|
+
rails g database NAME adapter:adapter_name db:database_name login:username psswd:password host:host_name port:port_number
|
7
|
+
|
8
|
+
NAME
|
9
|
+
name your database here (also applies on directory names and so on ...)
|
10
|
+
|
11
|
+
adapter
|
12
|
+
for now it supports:
|
13
|
+
* MySQL (as 'mysql')
|
14
|
+
* PostgreSQL (as 'pg')
|
15
|
+
* SQLite (as 'sqlite')
|
16
|
+
|
17
|
+
db
|
18
|
+
you can change the name of your database othervise it falls back to the NAME of your db (in most cases leave blank :) )
|
19
|
+
|
20
|
+
login
|
21
|
+
except sqlite, you can specify your DB credentials (this one stand for username)
|
22
|
+
|
23
|
+
psswd
|
24
|
+
except sqlite, you can specify your DB credentials (this one stands for password)
|
25
|
+
|
26
|
+
host
|
27
|
+
except sqlite, you can specify your DB credentials (this one stands for host, in most cases localhost)
|
28
|
+
|
29
|
+
port
|
30
|
+
except sqlite, you can specify your DB credentials (this one stands for port, in case of postgresql 5432)
|
31
|
+
|
7
32
|
|
8
33
|
This will create:
|
9
|
-
|
34
|
+
config config/database_store.yml
|
35
|
+
directory db_store
|
36
|
+
file db_store/.keep
|
37
|
+
directory db_store/migrate
|
38
|
+
file db_store/migrate/.keep
|
39
|
+
directory app/models/store
|
40
|
+
seeds db_store/seeds.rb
|
41
|
+
rake_task lib/tasks/database_store.rake
|
42
|
+
base_model app/models/store/base.rb
|
@@ -52,7 +52,7 @@ class DatabaseGenerator < Rails::Generators::NamedBase
|
|
52
52
|
attributes_with_defaults.each do |method_name, default|
|
53
53
|
define_method method_name.to_sym do
|
54
54
|
may_be_result = (attributes.find { |a| a.index_name.to_s == method_name.to_s })
|
55
|
-
(!may_be_result.nil? || may_be_result.is_a?(Rails::Generators::GeneratedAttribute)) ? may_be_result.type.to_s : default
|
55
|
+
(!may_be_result.nil? || may_be_result.is_a?(Rails::Generators::GeneratedAttribute)) ? may_be_result.type.to_s : ( (method_name.to_s == "db") ? file_name : default)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|