ar_after_transaction 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,9 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'rake'
4
+ gem 'rspec', '~>1.3'
5
+ gem 'jeweler'
4
6
  gem 'activerecord', :require => 'active_record'
7
+ gem 'mysql'
5
8
  gem 'activesupport', :require => 'active_support'
6
- gem 'sqlite3-ruby', :require => 'sqlite3'
9
+ gem 'sqlite3-ruby', :require => 'sqlite3'
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activerecord (2.3.9)
5
+ activesupport (= 2.3.9)
6
+ activesupport (2.3.9)
7
+ gemcutter (0.6.1)
8
+ git (1.2.5)
9
+ jeweler (1.4.0)
10
+ gemcutter (>= 0.1.0)
11
+ git (>= 1.2.5)
12
+ rubyforge (>= 2.0.0)
13
+ json_pure (1.4.6)
14
+ mysql (2.8.1)
15
+ rake (0.8.7)
16
+ rspec (1.3.0)
17
+ rubyforge (2.0.4)
18
+ json_pure (>= 1.1.7)
19
+ sqlite3-ruby (1.3.1)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ activerecord
26
+ activesupport
27
+ jeweler
28
+ mysql
29
+ rake
30
+ rspec (~> 1.3)
31
+ sqlite3-ruby
data/Readme.md CHANGED
@@ -1,4 +1,4 @@
1
- Perform stuff (only) after the currently open transactions have finished.
1
+ Do something only after the currently open transactions have finished.
2
2
 
3
3
  Normally everything gets rolled back when a transaction fails, but you cannot roll back sending an email or adding a job to Resque.
4
4
 
@@ -10,7 +10,7 @@ Its great for just-in-time callbacks:
10
10
  after_transaction do
11
11
  send_an_email # cannot be rolled back
12
12
  end
13
- comments.build(...) # can be rolled back
13
+ comments.create(...) # will be rolled back
14
14
  end
15
15
 
16
16
  def oops
@@ -24,11 +24,11 @@ Or general 'this should be rolled back when in a transaction code like jobs:
24
24
  def revertable_enqueue(*args)
25
25
  ActiveRecord::Base.after_transaction do
26
26
  enqueue(*args)
27
- end
27
+ end
28
28
  end
29
29
  end
30
30
 
31
- There is a after_commit hook in Rails 3, which can replace the first usage:
31
+ Alternative: after_commit hook in Rails 3, can replace the first usage:
32
32
 
33
33
  class User
34
34
  after_commit :send_an_email :on=>:create
@@ -36,7 +36,7 @@ There is a after_commit hook in Rails 3, which can replace the first usage:
36
36
  ...
37
37
  end
38
38
 
39
- after_transaction will behave like it would not exist if you are not in an transaction when calling it.
39
+ after_transaction will perform the given block imediatly if no transactions are open.
40
40
 
41
41
 
42
42
  rails plugin install git://github.com/grosser/ar_after_transaction
@@ -47,9 +47,12 @@ TODO
47
47
  - find out if we are in test mode with or without transactions (atm assumes depth of 1 for 'test' env)
48
48
 
49
49
 
50
- Author
51
- ======
52
- Original idea and code comes from: Jeremy Kemper @ https://rails.lighthouseapp.com/projects/8994/tickets/2991-after-transaction-patch
50
+ Authors
51
+ =======
52
+ [Original idea and code](https://rails.lighthouseapp.com/projects/8994/tickets/2991-after-transaction-patch) from [Jamis Buck](http://weblog.jamisbuck.org/) (post by Jeremy Kemper)
53
+
54
+ ### [Contributors](http://github.com/grosser/ar_after_transaction/contributors)
55
+ - [Bogdan Gusiev](http://gusiev.com)
53
56
 
54
57
 
55
58
  [Michael Grosser](http://pragmatig.wordpress.com)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,14 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ar_after_transaction}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2010-08-28}
12
+ s.date = %q{2010-10-14}
13
13
  s.email = %q{grosser.michael@gmail.com}
14
14
  s.files = [
15
15
  "Gemfile",
16
+ "Gemfile.lock",
16
17
  "Rakefile",
17
18
  "Readme.md",
18
19
  "VERSION",
@@ -22,8 +22,8 @@ module ARAfterTransaction
22
22
  raise
23
23
  ensure
24
24
  unless transactions_open?
25
- execute_after_transaction_callbacks if clean
26
- clear_transaction_callbacks
25
+ callbacks = delete_after_transaction_callbacks
26
+ callbacks.each(&:call) if clean
27
27
  end
28
28
  end
29
29
 
@@ -45,12 +45,10 @@ module ARAfterTransaction
45
45
  Rails.env.test? ? 1 : 0
46
46
  end
47
47
 
48
- def execute_after_transaction_callbacks
49
- @@after_transaction_hooks.each { |hook| hook.call }
50
- end
51
-
52
- def clear_transaction_callbacks
53
- @@after_transaction_hooks.clear
48
+ def delete_after_transaction_callbacks
49
+ result = @@after_transaction_hooks
50
+ @@after_transaction_hooks = []
51
+ result
54
52
  end
55
53
  end
56
54
 
@@ -59,4 +57,4 @@ module ARAfterTransaction
59
57
  end
60
58
  end
61
59
 
62
- ActiveRecord::Base.send(:include, ARAfterTransaction)
60
+ ActiveRecord::Base.send(:include, ARAfterTransaction)
@@ -15,6 +15,9 @@ class User
15
15
 
16
16
  def do_after
17
17
  after_transaction do
18
+ ActiveRecord::Base.transaction do
19
+ # nested transaction should not cause infinitive recursion
20
+ end
18
21
  self.class.test_stack << :after
19
22
  end
20
23
  end
@@ -85,4 +88,4 @@ describe ARAfterTransaction do
85
88
  }.should raise_error(AnExpectedError)
86
89
  User.test_stack.should == [:normal, :normal]
87
90
  end
88
- end
91
+ end
@@ -3,7 +3,7 @@ ActiveRecord::Base.establish_connection(
3
3
  :database => "ar_after_transaction"
4
4
  )
5
5
 
6
- ActiveRecord::Base.connection.execute('drop table users')
6
+ ActiveRecord::Base.connection.execute('drop table if exists users')
7
7
  ActiveRecord::Schema.define(:version => 1) do
8
8
  create_table :users do |t|
9
9
  t.string :name
@@ -15,4 +15,4 @@ end
15
15
  #ActiveRecord::Base.logger = Logger.new(STDOUT)
16
16
 
17
17
  class User < ActiveRecord::Base
18
- end
18
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser
@@ -14,12 +14,10 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-28 00:00:00 +02:00
17
+ date: 2010-10-14 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: activerecord
22
- prerelease: false
23
21
  requirement: &id001 !ruby/object:Gem::Requirement
24
22
  requirements:
25
23
  - - ">="
@@ -29,6 +27,8 @@ dependencies:
29
27
  version: "0"
30
28
  type: :runtime
31
29
  version_requirements: *id001
30
+ prerelease: false
31
+ name: activerecord
32
32
  description:
33
33
  email: grosser.michael@gmail.com
34
34
  executables: []
@@ -39,6 +39,7 @@ extra_rdoc_files: []
39
39
 
40
40
  files:
41
41
  - Gemfile
42
+ - Gemfile.lock
42
43
  - Rakefile
43
44
  - Readme.md
44
45
  - VERSION