ardb 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ardb.rb CHANGED
@@ -20,25 +20,28 @@ module Ardb
20
20
  end
21
21
  end
22
22
 
23
- def self.init(connection=true)
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
- ActiveRecord::Base.establish_connection(self.config.db.to_hash) if connection
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, :required => true
37
- option :database, String, :required => true
38
- option :encoding, String, :required => false
39
- option :url, String, :required => false
40
- option :username, String, :required => false
41
- option :password, String, :required => false
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
@@ -5,7 +5,7 @@ class Ardb::Adapter::Base
5
5
  attr_reader :config_settings, :database
6
6
 
7
7
  def initialize
8
- @config_settings = Ardb.config.db.to_hash
8
+ @config_settings = Ardb.config.db_settings
9
9
  @database = Ardb.config.db.database
10
10
  end
11
11
 
@@ -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.db.to_hash.inspect}"
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
@@ -1,3 +1,3 @@
1
1
  module Ardb
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -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.db.to_hash, subject.config_settings
18
+ assert_equal Ardb.config.db_settings, subject.config_settings
19
19
  end
20
20
 
21
21
  should "use the config's database" do
@@ -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, :required => true
34
- should have_option :database, String, :required => true
35
- should have_option :encoding, String, :required => false
36
- should have_option :url, String, :required => false
37
- should have_option :username, String, :required => false
38
- should have_option :password, String, :required => false
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
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ardb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding