after_commit 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -43,9 +43,9 @@ This version (maintained by Pat Allan) includes the following patches:
43
43
 
44
44
  * Callbacks for specific types of actions (create, update, destroy) ("DeLynn Berry":http://delynnberry.com/)
45
45
  * Fixes to extra callbacks ("Xavier Shay":http://rhnh.net/)
46
- * Gemspec and extended tests ("David Yip":http://github.com/yipdw)
47
46
  * Thread-safety ("Dmitry Galinsky":http://dima-exe.ru/)
48
47
  * after_rollback callback ("Justin Balthrop":http://github.com/ninjudd)
49
48
  * Test environment fix ("Pivotal Labs":http://pivotalblabs.com/)
50
49
  * Scoping callbacks to specific connections ("Mat Brown":http://outofti.me/)
51
50
  * before_* callbacks ("Trotter Cashion":http://trottercashion.com/)
51
+ * Gemspec and extended tests, works as a plugin, doesn't load ActiveRecord hooks twice, doesn't add Test environment hook automatically. ("David Yip":http://github.com/yipdw)
data/lib/after_commit.rb CHANGED
@@ -67,11 +67,4 @@ require 'after_commit/connection_adapters'
67
67
  require 'after_commit/test_bypass'
68
68
 
69
69
  ActiveRecord::Base.send(:include, AfterCommit::ActiveRecord)
70
-
71
- Object.subclasses_of(ActiveRecord::ConnectionAdapters::AbstractAdapter).each do |klass|
72
- klass.send(:include, AfterCommit::ConnectionAdapters)
73
- end
74
-
75
- if defined?(JRUBY_VERSION) and defined?(JdbcSpec::MySQL)
76
- JdbcSpec::MySQL.send :include, AfterCommit::ConnectionAdapters
77
- end
70
+ ActiveRecord::Base.include_after_commit_extensions
@@ -2,6 +2,34 @@ module AfterCommit
2
2
  module ActiveRecord
3
3
  def self.included(base)
4
4
  base.class_eval do
5
+ class << self
6
+ def establish_connection_with_after_commit(spec = nil)
7
+ establish_connection_without_after_commit spec
8
+ include_after_commit_extensions
9
+ end
10
+ alias_method_chain :establish_connection, :after_commit
11
+
12
+ def include_after_commit_extensions
13
+ base = ::ActiveRecord::ConnectionAdapters::AbstractAdapter
14
+ Object.subclasses_of(base).each do |klass|
15
+ include_after_commit_extension klass
16
+ end
17
+
18
+ if defined?(JRUBY_VERSION) and defined?(JdbcSpec::MySQL)
19
+ include_after_commit_extension JdbcSpec::MySQL
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def include_after_commit_extension(adapter)
26
+ additions = AfterCommit::ConnectionAdapters
27
+ unless adapter.included_modules.include?(additions)
28
+ adapter.send :include, additions
29
+ end
30
+ end
31
+ end
32
+
5
33
  # The define_callbacks method was added post Rails 2.0.2 - if it
6
34
  # doesn't exist, we define the callback manually
7
35
  if respond_to?(:define_callbacks)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: after_commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Muerdter
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-11-21 00:00:00 +11:00
14
+ date: 2009-11-25 00:00:00 +11:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -49,7 +49,6 @@ files:
49
49
  - lib/after_commit/active_record.rb
50
50
  - lib/after_commit/connection_adapters.rb
51
51
  - lib/after_commit/test_bypass.rb
52
- - rails/init.rb
53
52
  - README.textile
54
53
  has_rdoc: true
55
54
  homepage: http://github.com/freelancing-god/after_commit
data/rails/init.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'after_commit'
2
-
3
- ActiveRecord::Base.class_eval do
4
- include AfterCommit::ActiveRecord
5
- include AfterCommit::TestBypass if RAILS_ENV == 'test'
6
- end