wisper-active_tracker 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -15
- data/README.md +10 -21
- data/lib/wisper/active_tracker/tracker.rb +31 -35
- data/lib/wisper/active_tracker/version.rb +1 -1
- data/lib/wisper/active_tracker.rb +8 -6
- data/wisper-active_tracker.gemspec +15 -13
- metadata +37 -23
- data/.travis.yml +0 -11
- data/gemfiles/activerecord-3.0 +0 -12
- data/gemfiles/activerecord-4.0 +0 -12
- data/spec/spec_helper.rb +0 -48
- data/spec/support/models.rb +0 -3
- data/spec/support/schema.rb +0 -9
- data/spec/wisper/activechanges_spec.rb +0 -85
- data/spec/wisper/publisher_spec.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e78264d7de44631531b658fedef71c719898d930
|
4
|
+
data.tar.gz: b3d56509c0b63fdeffa9f76766da7f5f81db34e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27b34ab1ca2a4cb3580f68d9ecb60da21e71afe0ac5b8eb67714d31e4bcb44b0a30c4108c19334a385299f8302fbebc76ebb5d46077434729b6ca96e8e3584e9
|
7
|
+
data.tar.gz: ba239e2d86ad7df740f9630482482cde90c39f8c922e8252094a16b4d51e0acccccc855a1ab5b34f0ecf322e14c926bf309d8ad141c57190fdebfc960be41156
|
data/Gemfile
CHANGED
@@ -1,18 +1,3 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gemspec
|
4
|
-
|
5
|
-
gem 'rubysl', '~> 2.0', :platforms => :rbx
|
6
|
-
|
7
|
-
gem 'bundler', '~> 1.5'
|
8
|
-
gem 'rake'
|
9
|
-
gem 'rspec'
|
10
|
-
gem 'pry'
|
11
|
-
|
12
|
-
gem "sqlite3", :platform => :ruby
|
13
|
-
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
|
14
|
-
|
15
|
-
group :metrics do
|
16
|
-
gem 'flay'
|
17
|
-
gem 'simplecov'
|
18
|
-
end
|
data/README.md
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
# Wisper::
|
1
|
+
# Wisper::ActiveTracker
|
2
2
|
|
3
3
|
Transparently publish model lifecycle events to subscribers.
|
4
|
-
|
5
4
|
Using Wisper events is a better alternative to ActiveRecord callbacks and Observers.
|
6
|
-
|
7
5
|
Listeners are subscribed to models at runtime.
|
8
6
|
|
9
7
|
## Installation
|
10
8
|
|
11
9
|
```ruby
|
12
|
-
gem 'wisper-
|
10
|
+
gem 'wisper-active_tracker'
|
13
11
|
```
|
14
12
|
|
15
13
|
## Usage
|
@@ -18,17 +16,17 @@ gem 'wisper-activechanges'
|
|
18
16
|
|
19
17
|
```ruby
|
20
18
|
class Meeting < ActiveRecord::Base
|
21
|
-
include Wisper
|
19
|
+
include Wisper::ActiveTracker
|
22
20
|
|
23
21
|
# ...
|
24
22
|
end
|
25
23
|
```
|
26
24
|
|
27
25
|
If you wish all models to broadcast events without having to explicitly include
|
28
|
-
`Wisper
|
26
|
+
`Wisper::ActiveTracker` add the following to an initializer:
|
29
27
|
|
30
28
|
```ruby
|
31
|
-
Wisper::
|
29
|
+
Wisper::ActiveTracker.extend_all
|
32
30
|
```
|
33
31
|
|
34
32
|
### Subscribing
|
@@ -57,11 +55,14 @@ Please refer to the [Wisper README](https://github.com/krisleech/wisper) for ful
|
|
57
55
|
The events which are automatically broadcast are:
|
58
56
|
|
59
57
|
* `after_create`
|
60
|
-
* `after_create`
|
61
|
-
* `after_destroy`
|
62
58
|
* `create_<model_name>_{successful, failed}`
|
59
|
+
* `after_update`
|
63
60
|
* `update_<model_name>_{successful, failed}`
|
61
|
+
* `before_create`
|
62
|
+
* `after_destroy`
|
64
63
|
* `destroy_<model_name>_successful`
|
64
|
+
* `after_commit`
|
65
|
+
* `<model_name>_committed`
|
65
66
|
* `after_rollback`
|
66
67
|
|
67
68
|
### Reacting to Events
|
@@ -173,15 +174,3 @@ meeting.save
|
|
173
174
|
```ruby
|
174
175
|
Auditor.audit # => [...]
|
175
176
|
```
|
176
|
-
|
177
|
-
## Compatibility
|
178
|
-
|
179
|
-
## Contributing
|
180
|
-
|
181
|
-
Please submit a Pull Request with specs.
|
182
|
-
|
183
|
-
### Running the specs
|
184
|
-
|
185
|
-
```
|
186
|
-
bundle exec rspec
|
187
|
-
```
|
@@ -3,42 +3,43 @@ module Wisper
|
|
3
3
|
module Tracker
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
class_attribute :__tracker_options
|
18
|
-
self.__tracker_options = options.dup
|
19
|
-
end
|
6
|
+
included do
|
7
|
+
include Wisper::Publisher
|
8
|
+
|
9
|
+
after_validation :__track_after_validation_broadcast
|
10
|
+
after_commit :__track_after_create_broadcast, on: :create
|
11
|
+
after_commit :__track_after_update_broadcast, on: :update
|
12
|
+
after_commit :__track_after_destroy_broadcast, on: :destroy
|
13
|
+
after_commit :__track_after_commit_broadcast
|
14
|
+
after_rollback :__track_after_rollback_broadcast
|
15
|
+
before_destroy :__track_before_destroy_broadcast
|
20
16
|
end
|
21
17
|
|
22
18
|
private
|
23
19
|
|
24
20
|
def __track_after_validation_broadcast
|
25
21
|
action = new_record? ? 'create' : 'update'
|
26
|
-
broadcast("#{action}_#{
|
22
|
+
broadcast("#{action}_#{__tracker_broadcast_key}_failed", __tracker_args_broadcast) unless errors.empty?
|
27
23
|
end
|
28
24
|
|
29
25
|
def __track_after_create_broadcast
|
30
26
|
broadcast(:after_create, __tracker_args_broadcast)
|
31
|
-
broadcast("create_#{
|
27
|
+
broadcast("create_#{__tracker_broadcast_key}_successful", __tracker_args_broadcast)
|
32
28
|
end
|
33
29
|
|
34
30
|
def __track_after_update_broadcast
|
35
31
|
broadcast(:after_update, __tracker_args_broadcast)
|
36
|
-
broadcast("update_#{
|
32
|
+
broadcast("update_#{__tracker_broadcast_key}_successful", __tracker_args_broadcast)
|
37
33
|
end
|
38
34
|
|
39
35
|
def __track_after_destroy_broadcast
|
40
36
|
broadcast(:after_destroy, __tracker_args_broadcast)
|
41
|
-
broadcast("destroy_#{
|
37
|
+
broadcast("destroy_#{__tracker_broadcast_key}_successful", __tracker_args_broadcast)
|
38
|
+
end
|
39
|
+
|
40
|
+
def __track_after_commit_broadcast
|
41
|
+
broadcast(:after_commit, __tracker_args_broadcast)
|
42
|
+
broadcast("#{__tracker_broadcast_key}_committed", __tracker_args_broadcast)
|
42
43
|
end
|
43
44
|
|
44
45
|
def __track_after_rollback_broadcast
|
@@ -49,26 +50,21 @@ module Wisper
|
|
49
50
|
broadcast(:before_destroy, __tracker_args_broadcast)
|
50
51
|
end
|
51
52
|
|
52
|
-
def
|
53
|
-
|
54
|
-
|
55
|
-
args[:tenant] = Apartment::Tenant.current if defined?(Apartment)
|
56
|
-
|
57
|
-
if self.respond_to?(:tracker_args)
|
58
|
-
args.merge(self.tracker_args)
|
59
|
-
else
|
53
|
+
def __tracker_broadcast_key
|
54
|
+
self.class.model_name.param_key
|
55
|
+
end
|
60
56
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
57
|
+
def __tracker_args_broadcast
|
58
|
+
args = {
|
59
|
+
id: id,
|
60
|
+
global_id: to_global_id
|
61
|
+
}
|
66
62
|
|
67
|
-
|
68
|
-
|
69
|
-
end
|
63
|
+
args.merge(default_tracker_args) if respond_to?(:default_tracker_args)
|
64
|
+
args.merge(tracker_args) if respond_to?(:tracker_args)
|
70
65
|
|
71
|
-
|
66
|
+
args[:model] ||= self
|
67
|
+
args[:changes] ||= changes.dup
|
72
68
|
|
73
69
|
args
|
74
70
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'wisper/active_tracker/version'
|
2
|
+
require 'wisper/active_tracker/tracker'
|
3
3
|
|
4
4
|
module Wisper
|
5
|
-
def self.tracker
|
6
|
-
::Wisper::ActiveTracker::Tracker
|
7
|
-
end
|
8
|
-
|
9
5
|
module ActiveTracker
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
include Tracker
|
10
|
+
end
|
11
|
+
|
10
12
|
def self.extend_all
|
11
13
|
::ActiveRecord::Base.class_eval { include Wisper.tracker }
|
12
14
|
end
|
@@ -1,24 +1,26 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
4
|
require 'wisper/active_tracker/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'wisper-active_tracker'
|
8
8
|
spec.version = Wisper::ActiveTracker::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Mikko Kokkonen']
|
10
|
+
spec.email = ['mikko@mikian.com']
|
11
|
+
spec.summary = 'Subscribe to changes on ActiveRecord models'
|
12
|
+
spec.description = 'Subscribe to changes on ActiveRecord models'
|
13
|
+
spec.homepage = 'https://github.com/mikian/wisper-active_tracker'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
20
|
-
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'wisper', '~> 2.0'
|
22
|
+
spec.add_dependency 'activerecord', '>= 5.0.0'
|
21
23
|
|
22
|
-
spec.
|
23
|
-
spec.
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'sqlite3'
|
24
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wisper-active_tracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikko Kokkonen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wisper
|
@@ -16,28 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 5.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 5.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
description: Subscribe to changes on ActiveRecord models
|
42
70
|
email:
|
43
71
|
- mikko@mikian.com
|
@@ -47,21 +75,13 @@ extra_rdoc_files: []
|
|
47
75
|
files:
|
48
76
|
- ".gitignore"
|
49
77
|
- ".rspec"
|
50
|
-
- ".travis.yml"
|
51
78
|
- Gemfile
|
52
79
|
- LICENSE.txt
|
53
80
|
- README.md
|
54
81
|
- Rakefile
|
55
|
-
- gemfiles/activerecord-3.0
|
56
|
-
- gemfiles/activerecord-4.0
|
57
82
|
- lib/wisper/active_tracker.rb
|
58
83
|
- lib/wisper/active_tracker/tracker.rb
|
59
84
|
- lib/wisper/active_tracker/version.rb
|
60
|
-
- spec/spec_helper.rb
|
61
|
-
- spec/support/models.rb
|
62
|
-
- spec/support/schema.rb
|
63
|
-
- spec/wisper/activechanges_spec.rb
|
64
|
-
- spec/wisper/publisher_spec.rb
|
65
85
|
- wisper-active_tracker.gemspec
|
66
86
|
homepage: https://github.com/mikian/wisper-active_tracker
|
67
87
|
licenses:
|
@@ -75,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
95
|
requirements:
|
76
96
|
- - ">="
|
77
97
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
98
|
+
version: '0'
|
79
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
100
|
requirements:
|
81
101
|
- - ">="
|
@@ -83,14 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
103
|
version: '0'
|
84
104
|
requirements: []
|
85
105
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.6.13
|
87
107
|
signing_key:
|
88
108
|
specification_version: 4
|
89
109
|
summary: Subscribe to changes on ActiveRecord models
|
90
|
-
test_files:
|
91
|
-
- spec/spec_helper.rb
|
92
|
-
- spec/support/models.rb
|
93
|
-
- spec/support/schema.rb
|
94
|
-
- spec/wisper/activechanges_spec.rb
|
95
|
-
- spec/wisper/publisher_spec.rb
|
96
|
-
has_rdoc:
|
110
|
+
test_files: []
|
data/.travis.yml
DELETED
data/gemfiles/activerecord-3.0
DELETED
data/gemfiles/activerecord-4.0
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'simplecov'
|
3
|
-
SimpleCov.start do
|
4
|
-
add_filter 'spec'
|
5
|
-
end
|
6
|
-
rescue LoadError
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'wisper'
|
10
|
-
require 'active_record'
|
11
|
-
|
12
|
-
puts "Using ActiveRecord #{ActiveRecord::VERSION::STRING}"
|
13
|
-
|
14
|
-
adapter = RUBY_PLATFORM == "java" ? 'jdbcsqlite3' : 'sqlite3'
|
15
|
-
|
16
|
-
ActiveRecord::Base.establish_connection(:adapter => adapter,
|
17
|
-
:database => File.dirname(__FILE__) + "/db.sqlite3")
|
18
|
-
|
19
|
-
load File.dirname(__FILE__) + '/support/schema.rb'
|
20
|
-
|
21
|
-
require 'support/models'
|
22
|
-
|
23
|
-
require 'wisper/activechanges'
|
24
|
-
|
25
|
-
RSpec.configure do |config|
|
26
|
-
config.filter_run :focus
|
27
|
-
config.run_all_when_everything_filtered = true
|
28
|
-
|
29
|
-
if config.files_to_run.one?
|
30
|
-
config.full_backtrace = true
|
31
|
-
config.default_formatter = 'doc'
|
32
|
-
end
|
33
|
-
|
34
|
-
config.profile_examples = 10
|
35
|
-
|
36
|
-
config.order = :random
|
37
|
-
|
38
|
-
Kernel.srand config.seed
|
39
|
-
|
40
|
-
config.expect_with :rspec do |expectations|
|
41
|
-
expectations.syntax = :expect
|
42
|
-
end
|
43
|
-
|
44
|
-
config.mock_with :rspec do |mocks|
|
45
|
-
mocks.syntax = :expect
|
46
|
-
mocks.verify_partial_doubles = true
|
47
|
-
end
|
48
|
-
end
|
data/spec/support/models.rb
DELETED
data/spec/support/schema.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
describe 'ActiveChanges' do
|
2
|
-
let(:listener) { double('Listener') }
|
3
|
-
let(:model_class) { Class.new(Meeting) { include Wisper.model } }
|
4
|
-
|
5
|
-
before { Wisper::GlobalListeners.clear }
|
6
|
-
before { allow(model_class).to receive(:name).and_return('Meeting') }
|
7
|
-
|
8
|
-
it '.model returns ActiveChanges module' do
|
9
|
-
expect(Wisper.model).to eq Wisper::ActiveChanges::Publisher
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '.commit' do # DEPRECATED
|
13
|
-
describe 'when creating' do
|
14
|
-
context 'and model is valid' do
|
15
|
-
it 'publishes create_<model_name>_successful event to listener' do
|
16
|
-
expect(listener).to receive(:create_meeting_successful).with(instance_of(model_class))
|
17
|
-
model_class.subscribe(listener)
|
18
|
-
model_class.commit
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'and model is not valid' do
|
23
|
-
it 'publishes create_<model_name>_failed event to listener' do
|
24
|
-
expect(listener).to receive(:create_meeting_failed).with(instance_of(model_class))
|
25
|
-
model_class.subscribe(listener)
|
26
|
-
model_class.commit(title: nil)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'when updating' do
|
32
|
-
before { model_class.create! }
|
33
|
-
|
34
|
-
let(:model) { model_class.first }
|
35
|
-
|
36
|
-
context 'and model is valid' do
|
37
|
-
it 'publishes update_<model_name>_successful event to listener' do
|
38
|
-
expect(listener).to receive(:update_meeting_successful).with(instance_of(model_class))
|
39
|
-
model_class.subscribe(listener)
|
40
|
-
model.commit(title: 'foo')
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'and model is not valid' do
|
45
|
-
it 'publishes update_<model_name>_failed event to listener' do
|
46
|
-
expect(listener).to receive(:update_meeting_failed).with(instance_of(model_class))
|
47
|
-
model_class.subscribe(listener)
|
48
|
-
model.commit(title: nil)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe 'create' do
|
55
|
-
it 'publishes an after_create event to listener' do
|
56
|
-
expect(listener).to receive(:after_create).with(instance_of(model_class))
|
57
|
-
model_class.subscribe(listener)
|
58
|
-
model_class.create
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe 'update' do
|
63
|
-
before { model_class.create! }
|
64
|
-
|
65
|
-
let(:model) { model_class.first }
|
66
|
-
|
67
|
-
it 'publishes an after_update event to listener' do
|
68
|
-
expect(listener).to receive(:after_update).with(instance_of(model_class))
|
69
|
-
model.subscribe(listener)
|
70
|
-
model.update_attributes(title: 'new title')
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe 'destroy' do
|
75
|
-
before { model_class.create! }
|
76
|
-
|
77
|
-
let(:model) { model_class.first }
|
78
|
-
|
79
|
-
it 'publishes an on_destroy event to listener' do
|
80
|
-
expect(listener).to receive(:after_destroy).with(instance_of(model_class))
|
81
|
-
model_class.subscribe(listener)
|
82
|
-
model.destroy
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|