otr-activerecord 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58dbba472854748f534103046ed89afd5f6920f8
4
- data.tar.gz: eace235fb0201c8c3ba63a59cad9b4230fe3e707
3
+ metadata.gz: 55c44318e27db688423b06e978b3d7ea6e6a220f
4
+ data.tar.gz: 97c0947f0d97ccb7800d1a3a53712f6bc11d204a
5
5
  SHA512:
6
- metadata.gz: 2302a10494dfa0f20481b80318249aac5db711d7998390b15d48682ddf77d92173804f44ca0bae35e3ad576b886ae80f2bd65fa449c00272e954dabb5586a72f
7
- data.tar.gz: 42f5730e6b715517336ea15a337138293c1beadab4ea710be0f6005b5b29234f3e9ac2e17bdaba5e4efaeccbf2b18c6aada9a2882d5fdb49e593adcb355546d1
6
+ metadata.gz: 0f6b09947d9b7c1afe08725b22eb84bf8bcb7116c269575b451098c06895f21ae521a6ff37a32bd0fcc751d9a0dba76ef1d8c18c40049cd3a4c221142a971543
7
+ data.tar.gz: 8bfa485e127c84d927c71d5bde6a7091e46852614b79348f71f940dd65eb36d8c277ada0ff87bbaec2758fd1a9c02ea83efef8b34a6687d0bd24ab81a02b6e07
data/README.md CHANGED
@@ -24,9 +24,9 @@ This is because in ActiveRecord when that env variable is set it will merge its
24
24
 
25
25
  #### 3. Enable ActiveRecord connection management in Rack apps
26
26
 
27
- This ActiveRecord middleware cleans up your database connections after each request. Add it to your `config.ru` file:
27
+ This middleware cleans up your database connections after each request. Add it to your `config.ru` file:
28
28
 
29
- use ActiveRecord::ConnectionAdapters::ConnectionManagement
29
+ use OTR::ActiveRecord::ConnectionManagement
30
30
 
31
31
  #### 4. Import ActiveRecord tasks into your Rakefile
32
32
 
@@ -0,0 +1,26 @@
1
+ module OTR
2
+ module ActiveRecord
3
+ #
4
+ # Rack middleware that returns active db connections to the connection pool after a request completes.
5
+ #
6
+ class ConnectionManagement
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ testing = env['rack.test'] == true
13
+
14
+ resp = @app.call env
15
+ resp[2] = ::Rack::BodyProxy.new resp[2] do
16
+ ::ActiveRecord::Base.clear_active_connections! unless testing
17
+ end
18
+ resp
19
+
20
+ rescue Exception
21
+ ::ActiveRecord::Base.clear_active_connections! unless testing
22
+ raise
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,6 @@
1
1
  module OTR
2
2
  module ActiveRecord
3
3
  # Gem version
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
6
6
  end
@@ -4,4 +4,5 @@ require 'otr-activerecord/version'
4
4
  require 'otr-activerecord/activerecord'
5
5
  require 'otr-activerecord/compatibility_4'
6
6
  require 'otr-activerecord/compatibility_5'
7
+ require 'otr-activerecord/middleware/connection_management.rb'
7
8
  require 'otr-activerecord/defaults'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: otr-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-31 00:00:00.000000000 Z
11
+ date: 2016-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -58,6 +58,7 @@ files:
58
58
  - lib/otr-activerecord/compatibility_4.rb
59
59
  - lib/otr-activerecord/compatibility_5.rb
60
60
  - lib/otr-activerecord/defaults.rb
61
+ - lib/otr-activerecord/middleware/connection_management.rb
61
62
  - lib/otr-activerecord/version.rb
62
63
  - lib/tasks/otr-activerecord.rake
63
64
  homepage: https://github.com/jhollinger/otr-activerecord