wisper-activerecord 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +8 -2
- data/lib/wisper/active_record/publisher.rb +19 -4
- data/lib/wisper/active_record/version.rb +1 -1
- data/spec/wisper/activerecord_spec.rb +27 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abf0ef394a173a3870dc882787c583c98d5c78f5
|
4
|
+
data.tar.gz: 6183077725919d5ce4e5e3b1f917c79c847f77c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8053b1a558f92f4ccfa5e138122956a4266715852b7f89702111071dbc3fc8675856f7fad35ee36fbbbbce6eee795a084be4e8142813360c64744f400d16d8cb
|
7
|
+
data.tar.gz: 9aaadc00d223e96a5b66055697ce762f2e7eb17a688a9bc32f68d59e9d127563f0e8bc8a6c562b31801ce83b81ece3e90655e2a2dbbd52bc684c40d559624aa9
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
## 0.3.0 (5 Feb 2015)
|
2
|
+
|
3
|
+
* Fixed README (Thomas Brus / thomasbrus)
|
4
|
+
* Added `:after_commit` / `:<model_name>_committed` events (Ryan Platte / replaid)
|
5
|
+
|
6
|
+
## 0.2.0 (21 Oct 2014)
|
7
|
+
|
8
|
+
## 0.1.0 (14 Oct 2014)
|
9
|
+
|
10
|
+
* Initial implementation (Kris Leech / krisleech)
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Wisper::ActiveRecord
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/wisper-activerecord.png)](http://badge.fury.io/rb/wisper-activerecord)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/krisleech/wisper-activerecord.png)](https://codeclimate.com/github/krisleech/wisper-activerecord)
|
3
5
|
[![Build Status](https://travis-ci.org/krisleech/wisper-activerecord.png?branch=master)](https://travis-ci.org/krisleech/wisper-activerecord)
|
4
6
|
|
5
7
|
Transparently publish model lifecycle events to subscribers.
|
@@ -58,12 +60,13 @@ Please refer to the [Wisper README](https://github.com/krisleech/wisper) for ful
|
|
58
60
|
|
59
61
|
The events which are automatically broadcast are:
|
60
62
|
|
61
|
-
* `after_create`
|
62
63
|
* `after_create`
|
63
64
|
* `after_destroy`
|
64
65
|
* `create_<model_name>_{successful, failed}`
|
65
66
|
* `update_<model_name>_{successful, failed}`
|
66
67
|
* `destroy_<model_name>_successful`
|
68
|
+
* `<model_name>_committed`
|
69
|
+
* `after_commit`
|
67
70
|
* `after_rollback`
|
68
71
|
|
69
72
|
### Reacting to Events
|
@@ -109,6 +112,9 @@ class MeetingsController < ApplicationController
|
|
109
112
|
end
|
110
113
|
```
|
111
114
|
|
115
|
+
Using `on` to subscribe a block to handle the response is optional,
|
116
|
+
you can still use `if @meeting.save` if you prefer.
|
117
|
+
|
112
118
|
### Listener
|
113
119
|
|
114
120
|
**Which simply records an audit in memory**
|
@@ -150,7 +156,7 @@ class Auditor
|
|
150
156
|
action: action,
|
151
157
|
subject_id: subject.id,
|
152
158
|
subject_class: subject.class.to_s,
|
153
|
-
changes: subject.
|
159
|
+
changes: subject.previous_changes,
|
154
160
|
created_at: Time.now
|
155
161
|
}
|
156
162
|
end
|
@@ -10,6 +10,7 @@ module Wisper
|
|
10
10
|
after_commit :after_create_broadcast, on: :create
|
11
11
|
after_commit :after_update_broadcast, on: :update
|
12
12
|
after_commit :after_destroy_broadcast, on: :destroy
|
13
|
+
after_commit :after_commit_broadcast
|
13
14
|
after_rollback :after_rollback_broadcast
|
14
15
|
end
|
15
16
|
|
@@ -30,27 +31,41 @@ module Wisper
|
|
30
31
|
|
31
32
|
def after_validation_broadcast
|
32
33
|
action = new_record? ? 'create' : 'update'
|
33
|
-
broadcast("#{action}_#{
|
34
|
+
broadcast("#{action}_#{broadcast_model_name_key}_failed", self) unless errors.empty?
|
34
35
|
end
|
35
36
|
|
36
37
|
def after_create_broadcast
|
37
38
|
broadcast(:after_create, self)
|
38
|
-
broadcast("create_#{
|
39
|
+
broadcast("create_#{broadcast_model_name_key}_successful", self)
|
39
40
|
end
|
40
41
|
|
41
42
|
def after_update_broadcast
|
42
43
|
broadcast(:after_update, self)
|
43
|
-
broadcast("update_#{
|
44
|
+
broadcast("update_#{broadcast_model_name_key}_successful", self)
|
44
45
|
end
|
45
46
|
|
46
47
|
def after_destroy_broadcast
|
47
48
|
broadcast(:after_destroy, self)
|
48
|
-
broadcast("destroy_#{
|
49
|
+
broadcast("destroy_#{broadcast_model_name_key}_successful", self)
|
50
|
+
end
|
51
|
+
|
52
|
+
def after_commit_broadcast
|
53
|
+
broadcast(:after_commit, self)
|
54
|
+
broadcast("#{broadcast_model_name_key}_committed", self)
|
55
|
+
end
|
56
|
+
|
57
|
+
def after_commit_broadcast
|
58
|
+
broadcast(:after_commit, self)
|
59
|
+
broadcast("#{broadcast_model_name_key}_committed", self)
|
49
60
|
end
|
50
61
|
|
51
62
|
def after_rollback_broadcast
|
52
63
|
broadcast(:after_rollback, self)
|
53
64
|
end
|
65
|
+
|
66
|
+
def broadcast_model_name_key
|
67
|
+
self.class.model_name.param_key
|
68
|
+
end
|
54
69
|
end
|
55
70
|
end
|
56
71
|
end
|
@@ -76,10 +76,36 @@ describe 'ActiveRecord' do
|
|
76
76
|
|
77
77
|
let(:model) { model_class.first }
|
78
78
|
|
79
|
-
it 'publishes an
|
79
|
+
it 'publishes an after_destroy event to listener' do
|
80
80
|
expect(listener).to receive(:after_destroy).with(instance_of(model_class))
|
81
81
|
model_class.subscribe(listener)
|
82
82
|
model.destroy
|
83
83
|
end
|
84
84
|
end
|
85
|
+
|
86
|
+
describe 'commit' do
|
87
|
+
after do
|
88
|
+
model_class.subscribe(listener)
|
89
|
+
model_class.create
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'publishes an after_commit event to listener' do
|
93
|
+
expect(listener).to receive(:after_commit).with(instance_of(model_class))
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'publishes a <model_name>_committed event to listener' do
|
97
|
+
expect(listener).to receive(:meeting_committed).with(instance_of(model_class))
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'rollback' do
|
102
|
+
it 'publishes an after_rollback event to listener' do
|
103
|
+
expect(listener).to receive(:after_rollback).with(instance_of(model_class))
|
104
|
+
model_class.subscribe(listener)
|
105
|
+
model_class.transaction do
|
106
|
+
model_class.create!
|
107
|
+
raise ActiveRecord::Rollback
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
85
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wisper-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Leech
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wisper
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- ".gitignore"
|
49
49
|
- ".rspec"
|
50
50
|
- ".travis.yml"
|
51
|
+
- CHANGELOG.md
|
51
52
|
- Gemfile
|
52
53
|
- LICENSE.txt
|
53
54
|
- README.md
|