activerecord-committed_observer 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,7 +18,23 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Make sure you include CommittedObserver in any of the Observers you
22
+ want to hook after_commit methods on
23
+
24
+ ```ruby
25
+ class BigObserver < ::ActiveRecord::Observer
26
+ include ::ActiveRecord::CommittedObserver
27
+
28
+ def after_commit_on_create(big)
29
+ # do some things and stuff
30
+ end
31
+
32
+ def after_commit_on_update(big)
33
+ # Check `previous_changes` because it is after_commit!
34
+ end
35
+
36
+ end
37
+ ```
22
38
 
23
39
  ## Contributing
24
40
 
@@ -41,13 +41,26 @@ module ActiveRecord
41
41
  def after_commit(model)
42
42
  after_commit_on_commit(model) if respond_to?(:after_commit_on_commit)
43
43
 
44
- case
45
- when model.__send__(:transaction_include_action?, :create) then
46
- after_commit_on_create(model) if respond_to?(:after_commit_on_create)
47
- when model.__send__(:transaction_include_action?, :update) then
48
- after_commit_on_update(model) if respond_to?(:after_commit_on_update)
49
- when model.__send__(:transaction_include_action?, :destroy) then
50
- after_commit_on_destroy(model) if respond_to?(:after_commit_on_destroy)
44
+ if model.respond_to?(:transaction_include_any_action?, true)
45
+ # Rails 4
46
+ case
47
+ when model.__send__(:transaction_include_any_action?, [:create]) then
48
+ after_commit_on_create(model) if respond_to?(:after_commit_on_create)
49
+ when model.__send__(:transaction_include_any_action?, [:update]) then
50
+ after_commit_on_update(model) if respond_to?(:after_commit_on_update)
51
+ when model.__send__(:transaction_include_any_action?, [:destroy]) then
52
+ after_commit_on_destroy(model) if respond_to?(:after_commit_on_destroy)
53
+ end
54
+ else
55
+ # Rails 3
56
+ case
57
+ when model.__send__(:transaction_include_action?, :create) then
58
+ after_commit_on_create(model) if respond_to?(:after_commit_on_create)
59
+ when model.__send__(:transaction_include_action?, :update) then
60
+ after_commit_on_update(model) if respond_to?(:after_commit_on_update)
61
+ when model.__send__(:transaction_include_action?, :destroy) then
62
+ after_commit_on_destroy(model) if respond_to?(:after_commit_on_destroy)
63
+ end
51
64
  end
52
65
  end
53
66
 
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module CommittedObserver
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-committed_observer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-19 00:00:00.000000000 Z
12
+ date: 2014-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -105,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  segments:
107
107
  - 0
108
- hash: 376413514948801357
108
+ hash: -1875571285908965550
109
109
  required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  none: false
111
111
  requirements:
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  segments:
116
116
  - 0
117
- hash: 376413514948801357
117
+ hash: -1875571285908965550
118
118
  requirements: []
119
119
  rubyforge_project:
120
120
  rubygems_version: 1.8.24