deebee 0.0.1 → 0.0.2
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/deebee.rb +31 -18
- data/lib/deebee/version.rb +1 -1
- metadata +1 -1
data/lib/deebee.rb
CHANGED
@@ -7,32 +7,45 @@ require 'cgi'
|
|
7
7
|
|
8
8
|
module Deebee
|
9
9
|
class Error < StandardError; end
|
10
|
-
|
11
10
|
class ConnectionError < Error
|
12
|
-
def
|
13
|
-
@url = url
|
14
|
-
end
|
15
|
-
|
16
|
-
def message
|
17
|
-
"Invalid DATABASE_URL value: #{ENV['DATABASE_URL'].inspect}"
|
18
|
-
end
|
11
|
+
def message; 'Invalid DATABASE_URL or database.yml'; end
|
19
12
|
end
|
20
13
|
|
21
14
|
class App < Sinatra::Base
|
22
15
|
set :root, File.expand_path('../deebee', __FILE__)
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
before do
|
18
|
+
@@db ||= nil
|
19
|
+
|
20
|
+
unless @@db
|
21
|
+
begin
|
22
|
+
if ENV['DATABASE_URL']
|
23
|
+
@@db = Sequel.connect(ENV['DATABASE_URL'])
|
24
|
+
else
|
25
|
+
config = Rails.configuration.database_configuration[Rails.env]
|
26
|
+
|
27
|
+
# TODO Test other adapters
|
28
|
+
config['adapter'] = 'postgres' if config['adapter'] =~ /postgres/
|
29
|
+
|
30
|
+
@@db = Sequel.connect(
|
31
|
+
adapter: config['adapter'],
|
32
|
+
encoding: config['encoding'],
|
33
|
+
database: config['database'],
|
34
|
+
host: config['host'],
|
35
|
+
port: config['port'],
|
36
|
+
password: config['password'],
|
37
|
+
user: config['username'],
|
38
|
+
max_connections: config['pool'],
|
39
|
+
)
|
40
|
+
end
|
41
|
+
@@tables = @@db.tables.sort
|
42
|
+
rescue Sequel::Error, NameError
|
43
|
+
raise ConnectionError
|
44
|
+
end
|
30
45
|
end
|
31
|
-
end
|
32
46
|
|
33
|
-
|
34
|
-
@
|
35
|
-
@tables = settings.tables
|
47
|
+
@db = @@db
|
48
|
+
@tables = @@tables
|
36
49
|
redirect request.path_info.sub(/\/$/, '') if request.path_info =~ /.+\/$/
|
37
50
|
end
|
38
51
|
|
data/lib/deebee/version.rb
CHANGED