ardb 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/ardb.rb +18 -8
- data/lib/ardb/adapter/base.rb +1 -1
- data/lib/ardb/runner/connect_command.rb +2 -1
- data/lib/ardb/version.rb +1 -1
- data/test/unit/adapter/base_tests.rb +1 -1
- data/test/unit/config_tests.rb +17 -6
- metadata +3 -3
data/lib/ardb.rb
CHANGED
@@ -20,25 +20,28 @@ module Ardb
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.init(
|
23
|
+
def self.init(establish_connection=true)
|
24
24
|
validate!
|
25
25
|
Adapter.init
|
26
26
|
|
27
27
|
# setup AR
|
28
28
|
ActiveRecord::Base.logger = self.config.logger
|
29
|
-
|
29
|
+
if establish_connection
|
30
|
+
ActiveRecord::Base.establish_connection(self.config.db_settings)
|
31
|
+
end
|
30
32
|
end
|
31
33
|
|
32
34
|
class Config
|
33
35
|
include NsOptions::Proxy
|
34
36
|
|
35
37
|
namespace :db do
|
36
|
-
option :adapter, String,
|
37
|
-
option :database, String,
|
38
|
-
option :encoding, String,
|
39
|
-
option :
|
40
|
-
option :
|
41
|
-
option :
|
38
|
+
option :adapter, String, :required => true
|
39
|
+
option :database, String, :required => true
|
40
|
+
option :encoding, String, :required => false
|
41
|
+
option :host, String, :required => false
|
42
|
+
option :port, Integer, :required => false
|
43
|
+
option :username, String, :required => false
|
44
|
+
option :password, String, :required => false
|
42
45
|
end
|
43
46
|
|
44
47
|
option :root_path, Pathname, :required => true
|
@@ -46,6 +49,13 @@ module Ardb
|
|
46
49
|
option :migrations_path, RootPath, :default => proc{ "db/migrations" }
|
47
50
|
option :schema_path, RootPath, :default => proc{ "db/schema.rb" }
|
48
51
|
|
52
|
+
def self.db_settings
|
53
|
+
db.to_hash.inject({}) do |settings, (k, v)|
|
54
|
+
settings[k.to_s] = v if !v.nil?
|
55
|
+
settings
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
49
59
|
end
|
50
60
|
|
51
61
|
class Adapter
|
data/lib/ardb/adapter/base.rb
CHANGED
@@ -5,13 +5,14 @@ class Ardb::Runner::ConnectCommand
|
|
5
5
|
def run
|
6
6
|
begin
|
7
7
|
Ardb.init
|
8
|
+
ActiveRecord::Base.connection
|
8
9
|
$stdout.puts "connected to #{Ardb.config.db.adapter} db `#{Ardb.config.db.database}`"
|
9
10
|
rescue Ardb::Runner::CmdError => e
|
10
11
|
raise e
|
11
12
|
rescue Exception => e
|
12
13
|
$stderr.puts e, *e.backtrace
|
13
14
|
$stderr.puts "error connecting to #{Ardb.config.db.database.inspect} database"\
|
14
|
-
" with #{Ardb.config.
|
15
|
+
" with #{Ardb.config.db_settings.inspect}"
|
15
16
|
raise Ardb::Runner::CmdFail
|
16
17
|
end
|
17
18
|
end
|
data/lib/ardb/version.rb
CHANGED
@@ -15,7 +15,7 @@ class Ardb::Adapter::Base
|
|
15
15
|
should have_imeths :create_db, :drop_db
|
16
16
|
|
17
17
|
should "use the config's db settings " do
|
18
|
-
assert_equal Ardb.config.
|
18
|
+
assert_equal Ardb.config.db_settings, subject.config_settings
|
19
19
|
end
|
20
20
|
|
21
21
|
should "use the config's database" do
|
data/test/unit/config_tests.rb
CHANGED
@@ -13,6 +13,7 @@ class Ardb::Config
|
|
13
13
|
should have_option :root_path, Pathname, :required => true
|
14
14
|
should have_option :logger, :required => true
|
15
15
|
should have_options :migrations_path, :schema_path
|
16
|
+
should have_imeth :db_settings
|
16
17
|
|
17
18
|
should "should use `db/migrations` as the default migrations path" do
|
18
19
|
exp_path = Pathname.new(TESTDB_PATH).join("db/migrations").to_s
|
@@ -24,18 +25,28 @@ class Ardb::Config
|
|
24
25
|
assert_equal exp_path, subject.schema_path
|
25
26
|
end
|
26
27
|
|
28
|
+
should "build the db connection settings from the db configs" do
|
29
|
+
# returns only non-nil values with string keys
|
30
|
+
exp = {
|
31
|
+
'adapter' => "postgresql",
|
32
|
+
'database' => "ardbtest"
|
33
|
+
}
|
34
|
+
assert_equal exp, subject.db_settings
|
35
|
+
end
|
36
|
+
|
27
37
|
end
|
28
38
|
|
29
39
|
class DbTests < BaseTests
|
30
40
|
desc "db namespace"
|
31
41
|
subject{ Ardb::Config.db }
|
32
42
|
|
33
|
-
should have_option :adapter, String,
|
34
|
-
should have_option :database, String,
|
35
|
-
should have_option :encoding, String,
|
36
|
-
should have_option :
|
37
|
-
should have_option :
|
38
|
-
should have_option :
|
43
|
+
should have_option :adapter, String, :required => true
|
44
|
+
should have_option :database, String, :required => true
|
45
|
+
should have_option :encoding, String, :required => false
|
46
|
+
should have_option :host, String, :required => false
|
47
|
+
should have_option :port, Integer, :required => false
|
48
|
+
should have_option :username, String, :required => false
|
49
|
+
should have_option :password, String, :required => false
|
39
50
|
|
40
51
|
end
|
41
52
|
|
metadata
CHANGED