ardb 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ardb +1 -1
- data/lib/ardb/cli.rb +1 -5
- data/lib/ardb/runner.rb +4 -15
- data/lib/ardb/version.rb +1 -1
- data/test/helper.rb +3 -16
- data/test/unit/runner_tests.rb +2 -13
- metadata +8 -6
data/bin/ardb
CHANGED
data/lib/ardb/cli.rb
CHANGED
data/lib/ardb/runner.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
require 'ardb'
|
2
2
|
|
3
|
+
ENV['ARDB_CONFIG_FILE'] ||= 'config/db'
|
4
|
+
|
3
5
|
module Ardb; end
|
4
6
|
class Ardb::Runner
|
5
7
|
UnknownCmdError = Class.new(ArgumentError)
|
6
8
|
CmdError = Class.new(RuntimeError)
|
7
9
|
CmdFail = Class.new(RuntimeError)
|
8
10
|
|
9
|
-
attr_reader :cmd_name, :cmd_args, :opts
|
11
|
+
attr_reader :cmd_name, :cmd_args, :opts
|
10
12
|
|
11
13
|
def initialize(args, opts)
|
12
14
|
@opts = opts
|
13
15
|
@cmd_name = args.shift || ""
|
14
16
|
@cmd_args = args
|
15
|
-
@root_path = @opts.delete('root_path') || Dir.pwd
|
16
17
|
end
|
17
18
|
|
18
19
|
def run
|
@@ -43,22 +44,10 @@ class Ardb::Runner
|
|
43
44
|
private
|
44
45
|
|
45
46
|
def setup_run
|
46
|
-
|
47
|
-
DbConfigFile.new.require_if_exists
|
47
|
+
require ENV['ARDB_CONFIG_FILE']
|
48
48
|
Ardb.init(false) # don't establish a connection
|
49
49
|
end
|
50
50
|
|
51
|
-
class DbConfigFile
|
52
|
-
PATH = 'config/db.rb'
|
53
|
-
def initialize
|
54
|
-
@path = Ardb.config.root_path.join(PATH)
|
55
|
-
end
|
56
|
-
|
57
|
-
def require_if_exists
|
58
|
-
require @path.to_s if File.exists?(@path.to_s)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
51
|
class NullCommand
|
63
52
|
def run
|
64
53
|
# if this was a real command it would do something here
|
data/lib/ardb/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -2,23 +2,10 @@
|
|
2
2
|
# put any test helpers here
|
3
3
|
|
4
4
|
# add the root dir to the load path
|
5
|
-
|
6
|
-
$LOAD_PATH.unshift(ROOT_PATH)
|
5
|
+
$LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
|
7
6
|
|
8
7
|
# require pry for debugging (`binding.pry`)
|
9
8
|
require 'pry'
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
FileUtils.mkdir_p TESTDB_PATH
|
14
|
-
|
15
|
-
require 'logger'
|
16
|
-
require 'ardb'
|
17
|
-
Ardb.configure do |c|
|
18
|
-
c.root_path = TESTDB_PATH
|
19
|
-
c.logger = Logger.new($stdout)
|
20
|
-
|
21
|
-
c.db.adapter 'postgresql'
|
22
|
-
c.db.database 'ardbtest'
|
23
|
-
|
24
|
-
end
|
10
|
+
ENV['ARDB_CONFIG_FILE'] = 'tmp/testdb/config/db'
|
11
|
+
require ENV['ARDB_CONFIG_FILE']
|
data/test/unit/runner_tests.rb
CHANGED
@@ -12,7 +12,7 @@ class Ardb::Runner
|
|
12
12
|
end
|
13
13
|
subject{ @runner }
|
14
14
|
|
15
|
-
should have_readers :cmd_name, :cmd_args, :opts
|
15
|
+
should have_readers :cmd_name, :cmd_args, :opts
|
16
16
|
|
17
17
|
should "know its cmd, cmd_args, and opts" do
|
18
18
|
assert_equal 'null', subject.cmd_name
|
@@ -20,28 +20,17 @@ class Ardb::Runner
|
|
20
20
|
assert_equal 'opts', subject.opts['some']
|
21
21
|
end
|
22
22
|
|
23
|
-
should "default the 'root_path' opt to `Dir.pwd`" do
|
24
|
-
assert_equal Dir.pwd, subject.root_path
|
25
|
-
end
|
26
|
-
|
27
23
|
end
|
28
24
|
|
29
25
|
class RunTests < BaseTests
|
30
26
|
desc "when running a command"
|
31
27
|
setup do
|
32
|
-
@
|
33
|
-
@runner = Ardb::Runner.new(['null', 1, 2], 'root_path' => '/some/path')
|
28
|
+
@runner = Ardb::Runner.new(['null', 1, 2], {})
|
34
29
|
end
|
35
30
|
teardown do
|
36
|
-
Ardb.config.root_path = @orig_root_path
|
37
31
|
Ardb::Adapter.reset
|
38
32
|
end
|
39
33
|
|
40
|
-
should "set the Ardb config root_path" do
|
41
|
-
subject.run
|
42
|
-
assert_equal Pathname.new('/some/path'), Ardb.config.root_path
|
43
|
-
end
|
44
|
-
|
45
34
|
should "validate the configs" do
|
46
35
|
orig_adapter = Ardb.config.db.adapter
|
47
36
|
Ardb.config.db.adapter = nil
|
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:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-04-
|
19
|
+
date: 2013-04-18 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: assert
|
@@ -129,7 +129,7 @@ files:
|
|
129
129
|
- test/unit/runner_tests.rb
|
130
130
|
- test/unit/test_helpers_tests.rb
|
131
131
|
- tmp/.gitkeep
|
132
|
-
- tmp/
|
132
|
+
- tmp/mysqltest/.gitkeep
|
133
133
|
- tmp/pgtest/.gitkeep
|
134
134
|
- tmp/pgtest/Gemfile
|
135
135
|
- tmp/pgtest/Gemfile.lock
|
@@ -138,6 +138,8 @@ files:
|
|
138
138
|
- tmp/sqlitetest/Gemfile
|
139
139
|
- tmp/sqlitetest/Gemfile.lock
|
140
140
|
- tmp/sqlitetest/config/.gitkeep
|
141
|
+
- tmp/testdb/config/.gitkeep
|
142
|
+
- tmp/testdb/config/db.rb
|
141
143
|
homepage: http://github.com/redding/ardb
|
142
144
|
licenses: []
|
143
145
|
|