rails-app-installer 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rails-installer/databases.rb +52 -14
  2. metadata +2 -2
@@ -6,14 +6,17 @@ class RailsInstaller
6
6
  # database handler, subclass this class and define a +yml+ class and
7
7
  # optionally a +create_database+ method.
8
8
  class Database
9
- @@db_map = {}
9
+ @@db_map = Hash.new(self)
10
10
 
11
11
  # Connect to the database (using the 'database.yml' generated by the +yml+
12
12
  # method). Returns true if the database already exists, and false if the
13
13
  # database doesn't exist yet.
14
14
  def self.connect(installer)
15
+ database_yml = File.read File.join(installer.install_directory, 'config', 'database.yml') rescue nil
16
+ database_yml ||= yml(installer)
17
+
15
18
  ActiveRecord::Base.establish_connection(
16
- YAML.load(yml(installer))['production'])
19
+ YAML.load(database_yml)['production'])
17
20
  begin
18
21
  tables = ActiveRecord::Base.connection.tables
19
22
  if tables.size > 0
@@ -127,6 +130,7 @@ class RailsInstaller
127
130
  # nothing
128
131
  end
129
132
 
133
+ # Inheritence hook
130
134
  def self.inherited(sub)
131
135
  name = sub.to_s.gsub(/^.*::/,'').gsub(/([A-Z])/) do |match|
132
136
  "_#{match.downcase}"
@@ -138,6 +142,21 @@ class RailsInstaller
138
142
  def self.dbs
139
143
  @@db_map
140
144
  end
145
+
146
+ # Database host name
147
+ def self.db_host(installer)
148
+ installer.config['db_host'] || 'localhost'
149
+ end
150
+
151
+ # Database user name
152
+ def self.db_user(installer)
153
+ installer.config['db_user'] || ENV['USER'] || installer.app_name
154
+ end
155
+
156
+ # Database name
157
+ def self.db_name(installer)
158
+ installer.config['db_name'] || installer.app_name
159
+ end
141
160
 
142
161
  # The driver for SQLite 3. This is pretty minimal, as all we need is a
143
162
  # +yml+ class to provide a basic 'database.yml'.
@@ -177,18 +196,6 @@ class RailsInstaller
177
196
  #
178
197
  # It will call +createdb+ to set up the db all on its own.
179
198
  class Postgresql < RailsInstaller::Database
180
- def self.db_host(installer)
181
- installer.config['db_host'] || 'localhost'
182
- end
183
-
184
- def self.db_user(installer)
185
- installer.config['db_user'] || ENV['USER'] || installer.app_name
186
- end
187
-
188
- def self.db_name(installer)
189
- installer.config['db_name'] || installer.app_name
190
- end
191
-
192
199
  def self.yml(installer)
193
200
  %Q{
194
201
  login: &login
@@ -217,5 +224,36 @@ class RailsInstaller
217
224
  system("createdb -U #{db_user installer} #{db_name installer}-test")
218
225
  end
219
226
  end
227
+
228
+ # Mysql DB class, thanks Phillip Toland
229
+ class Mysql < RailsInstaller::Database
230
+ def self.yml(installer)
231
+ %Q{
232
+ login: &login
233
+ adapter: mysql
234
+ host: #{db_host installer}
235
+ username: #{db_user installer}
236
+ password: #{installer.config['db_password']}
237
+ database: #{db_name installer}
238
+
239
+ development:
240
+ <<: *login
241
+
242
+ production:
243
+ <<: *login
244
+
245
+ test:
246
+ database: #{db_name installer}-test
247
+ <<: *login
248
+ }
249
+ end
250
+
251
+ # Create a MySQL database.
252
+ def self.create_database(installer)
253
+ installer.message "Creating MySQL database"
254
+ system("mysql -u #{db_user installer} -p#{installer.config['db_password']} -e 'create database #{db_name installer}'")
255
+ system("mysql -u #{db_user installer} -p#{installer.config['db_password']} -e 'create database #{db_name installer}-test'")
256
+ end
257
+ end
220
258
  end
221
259
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: rails-app-installer
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2006-08-09 00:00:00 -07:00
6
+ version: 0.1.2
7
+ date: 2006-08-10 00:00:00 -07:00
8
8
  summary: An installer for Rails apps
9
9
  require_paths:
10
10
  - lib