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.
Files changed (3) hide show
  1. data/lib/deebee.rb +31 -18
  2. data/lib/deebee/version.rb +1 -1
  3. metadata +1 -1
@@ -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 initialize(url)
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
- configure do
25
- begin
26
- set :db, Sequel.connect(ENV['DATABASE_URL'])
27
- set :tables, settings.db.tables.sort
28
- rescue Sequel::Error
29
- raise ConnectionError.new(ENV['DATABASE_URL'])
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
- before do
34
- @db = settings.db
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
 
@@ -1,3 +1,3 @@
1
1
  module Deebee
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deebee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: