wisper_plus 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
+ SHA256:
3
+ metadata.gz: 9d600365a12c2f4160ec3c6559f374ae2c085c96833677b55bf761cfac9845f1
4
+ data.tar.gz: 2c47e6f91ab1751ad9cb2851677d4179fc3c1a352e11ff971260cf18f4ca3aef
5
+ SHA512:
6
+ metadata.gz: 5e9b0fce3f74b4d25ad1fc88d608d997584741fe41637e4c2e9e617c6fe2a8c6e3e9f1ad47ff7819a318a1e9ccdd0ee60dc017796cf48017d843640f9df0b47f
7
+ data.tar.gz: b8e92c159efecea5308163c7e023b38b2a9a7b76e0fa577566b4aaf9b9cddd02b18fb97d97742fbd349a1b4cc153343282271a794e26b6dd9b4230406e423dff
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in wisper_plus.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ben Sharpe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # WisperPlus
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/wisper_plus`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'wisper_plus'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install wisper_plus
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wisper_plus.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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_plus"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ require 'rails'
2
+
3
+ class WisperPlus::Railtie < Rails::Railtie
4
+
5
+ config.after_initialize do
6
+
7
+ # Link any Models to their <Model>Subscriber class
8
+ Dir.glob(Rails.root.join('app/models/**/*.rb').to_s) do |filename|
9
+ next if filename.index('/concerns/')
10
+ filename = filename.remove(Rails.root.join('app/models/').to_s)[0..-4]
11
+ klass = filename.camelize.constantize
12
+ next unless klass.ancestors.include?(ApplicationRecord)
13
+ begin
14
+ notifier_klass = "#{klass}Subscriber".constantize
15
+ klass.subscribe(notifier_klass.new, async: false)
16
+ if Rails.env.development?
17
+ puts "🔹 #{klass.to_s.magenta} #{'subscriber'.blue}"
18
+ end
19
+ if !klass.ancestors.include?(Wisper::Publisher)
20
+ puts "🔸 #{klass} is not including Wisper::ActiveRecord::Publisher".yellow
21
+ end
22
+ rescue NameError
23
+ # ignore
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,3 @@
1
+ module WisperPlus
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,89 @@
1
+ require "wisper_plus/version"
2
+ require 'wisper_plus/railtie'
3
+ require 'wisper'
4
+
5
+ ### ACTIVERECORD SUPPORT
6
+ module Wisper
7
+ module ActiveRecord
8
+ # ActiveRecord extension to automatically publish events for CRUD lifecycle
9
+ # see https://github.com/krisleech/wisper/wiki/Rails-CRUD-with-ActiveRecord
10
+ # see https://github.com/krisleech/wisper-activerecord
11
+ module Publisher
12
+ extend ActiveSupport::Concern
13
+ include Wisper::Publisher
14
+
15
+ included do
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(:after_create, 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(:after_update, self, previous_changes.with_indifferent_access) if previous_changes.any?
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(:after_destroy, attributes.with_indifferent_access)
40
+ end
41
+ end
42
+ end
43
+
44
+ ### ACTIVEJOB SUPPORT
45
+ if defined?(ActiveJob)
46
+ class ActiveJobBroadcaster
47
+ def broadcast(subscriber, publisher, event, args)
48
+ # Turn objects in args into GlobalID strings
49
+ args = args.map { |e| e.respond_to?(:to_global_id) ? e.to_global_id.to_s : e }
50
+ Wrapper.perform_later(subscriber.class.name, event, JSON.dump(args))
51
+ end
52
+
53
+ class Wrapper < ::ActiveJob::Base
54
+ queue_as :default
55
+
56
+ def perform(class_name, event, args)
57
+ listener = class_name.constantize.new
58
+ if listener.respond_to?(event)
59
+ args = JSON.parse(args).map do |e|
60
+ if e.is_a?(String) && e.starts_with?("gid://")
61
+ begin
62
+ GlobalID::Locator.locate(e)
63
+ rescue ActiveRecord::RecordNotFound
64
+ listener = nil
65
+ end
66
+ else
67
+ e
68
+ end
69
+ end
70
+ ap event
71
+ listener&.public_send(event, *args)
72
+ end
73
+ end
74
+ end
75
+
76
+ def self.register
77
+ Wisper.configure do |config|
78
+ config.broadcaster :active_job, ActiveJobBroadcaster.new
79
+ config.broadcaster :async, ActiveJobBroadcaster.new
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ Wisper::ActiveJobBroadcaster.register
86
+ end
87
+
88
+
89
+
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "wisper_plus/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wisper_plus"
8
+ spec.version = WisperPlus::VERSION
9
+ spec.authors = ["Ben Sharpe"]
10
+ spec.email = ["bsharpe@gmail.com"]
11
+
12
+ spec.summary = %q{Handy additions to Wisper}
13
+ spec.description = %q{Add ActiveRecord callback support; ActiveJob support and Automagic connection of subscriber classes to publisher models}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ # # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/}) || f.match(%r{\.gem$})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+
36
+ spec.add_runtime_dependency 'activesupport', '>= 3', '< 6'
37
+
38
+ spec.add_dependency 'wisper', '>= 1.6', '< 3.0'
39
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wisper_plus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Sharpe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '6'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '3'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '6'
61
+ - !ruby/object:Gem::Dependency
62
+ name: wisper
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '1.6'
68
+ - - "<"
69
+ - !ruby/object:Gem::Version
70
+ version: '3.0'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '1.6'
78
+ - - "<"
79
+ - !ruby/object:Gem::Version
80
+ version: '3.0'
81
+ description: Add ActiveRecord callback support; ActiveJob support and Automagic connection
82
+ of subscriber classes to publisher models
83
+ email:
84
+ - bsharpe@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/wisper_plus.rb
99
+ - lib/wisper_plus/railtie.rb
100
+ - lib/wisper_plus/version.rb
101
+ - wisper_plus.gemspec
102
+ homepage: ''
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.7.6
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Handy additions to Wisper
126
+ test_files: []