wisper-activerecord-publisher 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dbbf26c397308935a96d6ca2937459bf72bdb08f
4
+ data.tar.gz: 3208f1be800e7b9657c524d279ef6f3bf9b2ff8d
5
+ SHA512:
6
+ metadata.gz: 5871dfbb1ca88685f617cd6ae490788c295580d946f7bbc9b9afbaaff3537cbb1c2a282cbc9e373901be615ec186e5e0bca7708e0be89cce092e26a7419f4453
7
+ data.tar.gz: ca155564536f17f0680d5207e86c251b5c79ec08e817a57a4ca0bffdfa8bc1af2a750d4a78ece3c8caf3041987cde5fd33626d01f0cae378da042868606932c4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wisper-activerecord-publisher.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Wisper::Activerecord::Publisher
2
+ > Extract logic from your callbacks into wisper listeners for model events
3
+ (create, update, delete)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'wisper-activerecord-publisher'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ Create a wisper listener with methods named to match any of the supported
20
+ broadcast events:
21
+ * MODEL_created - event is published after record created in DB
22
+ * MODEL_updated - event is published after record is updated and includes attributes that changed
23
+ * MODEL_destroyed - event is published after record is destroyed and includes a read-only copy of the model attributes
24
+
25
+ This gem *does* support background event processing since the events are
26
+ published after commit and each event includes the necessary payload (ie:
27
+ changes).
28
+
29
+ ## Example
30
+
31
+ ```ruby
32
+ class Foo < ActiveRecord::Base
33
+ end
34
+
35
+ class MyListener
36
+ def foo_created(model)
37
+ # do something here with the model
38
+ end
39
+
40
+ def foo_updated(model, changes)
41
+ end
42
+
43
+ def foo_destroyed(model_attributes)
44
+ # read-only copy of attributes
45
+ # model is already deleted from database
46
+ end
47
+ end
48
+ ```
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+
54
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/betterup/wisper-activerecord-publisher.
59
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wisper/activerecord/publisher"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,50 @@
1
+ require 'wisper/activerecord/publisher/version'
2
+ require 'active_record'
3
+ require 'wisper'
4
+
5
+ module Wisper
6
+ module ActiveRecord
7
+ # ActiveRecord extension to automatically publish events for CRUD lifecycle
8
+ # see https://github.com/krisleech/wisper/wiki/Rails-CRUD-with-ActiveRecord
9
+ # see https://github.com/krisleech/wisper-activerecord
10
+ module Publisher
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ include Wisper::Publisher
15
+
16
+ after_commit :broadcast_create, on: :create
17
+ after_commit :broadcast_update, on: :update
18
+ after_commit :broadcast_destroy, on: :destroy
19
+ end
20
+
21
+ private
22
+
23
+ # broadcast MODEL_created event to subscribed listeners
24
+ def broadcast_create
25
+ broadcast broadcast_event_name(:created), self
26
+ end
27
+
28
+ # broadcast MODEL_updated event to subscribed listeners
29
+ # pass the set of changes for background jobs to know what changed
30
+ # see https://github.com/krisleech/wisper-activerecord/issues/17
31
+ def broadcast_update
32
+ broadcast broadcast_event_name(:updated), self, previous_changes
33
+ end
34
+
35
+ # broadcast MODEL_destroyed to subscribed listeners
36
+ # pass a serialized version of the object attributes
37
+ # for listeners since the object is no longer accessible in the database
38
+ def broadcast_destroy
39
+ broadcast broadcast_event_name(:destroyed), attributes
40
+ end
41
+
42
+ def broadcast_event_name(lifecycle)
43
+ "#{self.class.model_name.param_key}_#{lifecycle}"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ ActiveSupport.on_load(:active_record) do
49
+ include Wisper::ActiveRecord::Publisher
50
+ end
@@ -0,0 +1,7 @@
1
+ module Wisper
2
+ module Activerecord
3
+ module Publisher
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wisper/activerecord/publisher/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'wisper-activerecord-publisher'
8
+ spec.version = Wisper::Activerecord::Publisher::VERSION
9
+ spec.authors = ['BetterUp Developers']
10
+ spec.email = ['developers@betterup.co']
11
+
12
+ spec.summary = 'Publish wisper events for activerecord model lifecycle'
13
+ spec.homepage = 'https://github.com/betterup/wisper-activerecord-publisher'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = 'exe'
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_runtime_dependency 'wisper'
21
+ spec.add_runtime_dependency 'activerecord'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.10'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec'
26
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wisper-activerecord-publisher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - BetterUp Developers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: wisper
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - developers@betterup.co
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/wisper/activerecord/publisher.rb
99
+ - lib/wisper/activerecord/publisher/version.rb
100
+ - wisper-activerecord-publisher.gemspec
101
+ homepage: https://github.com/betterup/wisper-activerecord-publisher
102
+ licenses: []
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.4.8
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Publish wisper events for activerecord model lifecycle
124
+ test_files: []
125
+ has_rdoc: