rack-databases 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,10 @@
1
1
  module Rack
2
2
  class Databases
3
3
 
4
+ def self.current
5
+ @current ||= 'default'
6
+ end
7
+
4
8
  def initialize(app, options = {})
5
9
  @app = app
6
10
  end
@@ -9,8 +13,10 @@ module Rack
9
13
  request = Rack::Request.new(env)
10
14
  if request.path =~ /^\/__database__\/(.*)/
11
15
  begin
12
- ActiveRecord::Base.establish_connection($1)
13
- [200, {'Content-Type' => 'text/plain'}, ["Switched to #$1 database"]]
16
+ nxt = $1
17
+ ActiveRecord::Base.establish_connection(nxt)
18
+ Rack::Databases.instance_variable_set("@current", nxt)
19
+ [200, {'Content-Type' => 'text/plain'}, ["Switched to #{nxt} database"]]
14
20
  rescue => ex
15
21
  [500, {'Content-Type' => 'text/plain'}, [ex.message]]
16
22
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Databases
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-databases
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Burke Libbey