pubsub_notifier 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/generators/pubsub_notifier/install/install_generator.rb +9 -7
- data/lib/generators/pubsub_notifier/install/templates/{application_notifier.rb → application_notifier.tt} +0 -0
- data/lib/generators/pubsub_notifier/install/templates/initializer.tt +10 -0
- data/lib/generators/rails/notifier_generator.rb +3 -2
- data/lib/generators/rails/templates/{notifier.rb → notifier.tt} +2 -4
- data/lib/generators/rspec/notifier_generator.rb +6 -4
- data/lib/generators/rspec/templates/notifier_spec.tt +5 -0
- data/lib/generators/test_unit/notifier_generator.rb +6 -4
- data/lib/generators/test_unit/templates/notifier_test.tt +6 -0
- data/lib/pubsub_notifier/acts_as_notifier.rb +7 -2
- data/lib/pubsub_notifier/base.rb +1 -1
- data/lib/pubsub_notifier/broadcasters/active_job_broadcaster.rb +5 -5
- data/lib/pubsub_notifier/client.rb +2 -1
- data/lib/pubsub_notifier/proxy.rb +2 -2
- data/lib/pubsub_notifier/slack_client.rb +15 -15
- data/lib/pubsub_notifier/version.rb +1 -1
- metadata +7 -7
- data/lib/generators/pubsub_notifier/install/templates/initializer.rb +0 -10
- data/lib/generators/rspec/templates/notifier_spec.rb +0 -5
- data/lib/generators/test_unit/templates/notifier_test.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbf75609870b5f43818cd6ca1c2b320bbf1ad2fe
|
4
|
+
data.tar.gz: 7ead5b1b9bfe7e0f432bd7267277b38bba21393f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d39a9e1533fda09d47a66de943b58442d7cff8ea77fd9fcb19a1f9b3f5e0f91cc77a39c948ecbf59526662258a140880768a1623ebb51e756a7097c75586291
|
7
|
+
data.tar.gz: 06e2db840248b5c0f1d84138b8ad50806f3916baf79e01672eda2e9d9c5c35721f12fccd1f2ea6cbbf01c846480382d3f6f9a9cb9c59db6da6f5c576e13cbf04
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# PubsubNotifier
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/yhirano55/pubsub_notifier.svg?branch=master)](https://travis-ci.org/yhirano55/pubsub_notifier)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/pubsub_notifier.svg)](https://badge.fury.io/rb/pubsub_notifier)
|
5
|
+
|
3
6
|
Publish-Subscribe Notifier for Ruby on Rails.
|
4
7
|
|
5
8
|
This gem relies on [krisleech/wisper](https://github.com/krisleech/wisper/) provides Pub/Sub capabilities.
|
@@ -1,13 +1,15 @@
|
|
1
1
|
module PubsubNotifier
|
2
|
-
|
3
|
-
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < ::Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def create_initializer_file
|
7
|
+
template "initializer.tt", "config/initializers/pubsub_notifier.rb"
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
def create_application_notifier_file
|
11
|
+
template "application_notifier.tt", "app/notifiers/application_notifier.rb"
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
PubsubNotifier.config.logger = Rails.logger
|
2
|
+
|
3
|
+
require "pubsub_notifier/slack_client"
|
4
|
+
|
5
|
+
PubsubNotifier::SlackClient.configure do |config|
|
6
|
+
config.default_channel = ENV["SLACK_DEFAULT_CHANNEL"]
|
7
|
+
config.default_username = ENV["SLACK_DEFAULT_USERNAME"]
|
8
|
+
config.default_icon_emoji = ENV["SLACK_DEFAULT_ICON_EMOJI"]
|
9
|
+
config.webhook_url = ENV["SLACK_WEBHOOK_URL"]
|
10
|
+
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module Rails
|
2
2
|
module Generators
|
3
|
-
class NotifierGenerator <
|
3
|
+
class NotifierGenerator < NamedBase
|
4
4
|
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
check_class_collision suffix: "Notifier"
|
5
6
|
|
6
7
|
def create_notifier_file
|
7
|
-
template
|
8
|
+
template "notifier.tt", File.join("app/notifiers", class_path, "#{file_name}_notifier.rb")
|
8
9
|
end
|
9
10
|
|
10
11
|
hook_for :test_framework
|
@@ -3,13 +3,11 @@ class <%= class_name %>Notifier < ApplicationNotifier
|
|
3
3
|
use :slack
|
4
4
|
|
5
5
|
def success(recipient)
|
6
|
-
|
7
|
-
notify_success("#{record} has successfully created.")
|
6
|
+
notify_success("#{self.class}##{__method__} called with #{recipient.class}.")
|
8
7
|
end
|
9
8
|
|
10
9
|
def failure(recipient)
|
11
|
-
|
12
|
-
notify_failure("#{record} cannot created.")
|
10
|
+
notify_failure("#{self.class}##{__method__} called with #{recipient.class}.")
|
13
11
|
end
|
14
12
|
end
|
15
13
|
<% end -%>
|
@@ -1,9 +1,11 @@
|
|
1
1
|
module RSpec
|
2
|
-
|
3
|
-
|
2
|
+
module Generators
|
3
|
+
class NotifierGenerator < ::Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
def create_spec_file
|
7
|
+
template "notifier_spec.tt", File.join("spec/notifiers", class_path, "#{file_name}_notifier_spec.rb")
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
module TestUnit
|
2
|
-
|
3
|
-
|
2
|
+
module Generators
|
3
|
+
class NotifierGenerator < ::Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
def create_test_file
|
7
|
+
template "notifier_test.tt", File.join("test/notifiers", class_path, "#{file_name}_notifier_test.rb")
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
@@ -5,12 +5,13 @@ module PubsubNotifier
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
+
# Override ActionMailer::Base.method_missing
|
9
|
+
# https://github.com/rails/rails/blob/master/actionmailer/lib/action_mailer/base.rb#L576
|
8
10
|
def acts_as_notifier
|
9
11
|
class_eval do
|
10
12
|
class << self
|
11
13
|
private
|
12
|
-
|
13
|
-
# https://github.com/rails/rails/blob/master/actionmailer/lib/action_mailer/base.rb#L576
|
14
|
+
|
14
15
|
def method_missing(method_name, *args)
|
15
16
|
if action_methods.include?(method_name.to_s)
|
16
17
|
::ActionMailer::MessageDelivery.new(self, method_name, *args).tap(&:deliver)
|
@@ -18,6 +19,10 @@ module PubsubNotifier
|
|
18
19
|
super
|
19
20
|
end
|
20
21
|
end
|
22
|
+
|
23
|
+
def respond_to_missing?(method_name, include_all = false)
|
24
|
+
action_methods.include?(method_name.to_s) || super
|
25
|
+
end
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
data/lib/pubsub_notifier/base.rb
CHANGED
@@ -19,12 +19,12 @@ module PubsubNotifier
|
|
19
19
|
{ wait: nil, wait_until: nil, queue: :default }
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
class BroadcastJob < ::ActiveJob::Base
|
23
|
+
def perform(subscriber_name, event, args)
|
24
|
+
subscriber = subscriber_name.constantize
|
25
|
+
subscriber.public_send(event, *args)
|
26
|
+
end
|
26
27
|
end
|
27
|
-
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -7,7 +7,7 @@ module PubsubNotifier
|
|
7
7
|
module ClassMethods
|
8
8
|
def subscribe(subscriber_name, options = {})
|
9
9
|
subscriber = subscriber_name.to_s.constantize
|
10
|
-
broadcaster = (
|
10
|
+
broadcaster = (options.delete(:async) ? broadcasters[:async] : nil) || broadcasters[:default]
|
11
11
|
broadcaster.configure(options) if broadcaster.respond_to?(:configure)
|
12
12
|
pubsub.subscribe(subscriber, broadcaster: broadcaster)
|
13
13
|
end
|
@@ -27,7 +27,7 @@ module PubsubNotifier
|
|
27
27
|
pubsub.call(event, self)
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
alias_method :pubilish, :broadcast
|
31
31
|
|
32
32
|
private
|
33
33
|
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "net/http"
|
2
|
+
require "json"
|
3
|
+
require "uri"
|
4
4
|
|
5
5
|
module PubsubNotifier
|
6
6
|
class SlackClient < ::PubsubNotifier::Client::Base
|
@@ -16,8 +16,8 @@ module PubsubNotifier
|
|
16
16
|
post_slack(
|
17
17
|
attachments: [{
|
18
18
|
text: message,
|
19
|
-
color:
|
20
|
-
mrkdwn_in: [
|
19
|
+
color: "good",
|
20
|
+
mrkdwn_in: ["text"],
|
21
21
|
}],
|
22
22
|
)
|
23
23
|
end
|
@@ -26,8 +26,8 @@ module PubsubNotifier
|
|
26
26
|
post_slack(
|
27
27
|
attachments: [{
|
28
28
|
text: message,
|
29
|
-
color:
|
30
|
-
mrkdwn_in: [
|
29
|
+
color: "danger",
|
30
|
+
mrkdwn_in: ["text"],
|
31
31
|
}],
|
32
32
|
)
|
33
33
|
end
|
@@ -70,16 +70,16 @@ module PubsubNotifier
|
|
70
70
|
config.webhook_url
|
71
71
|
end
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
class Config
|
74
|
+
attr_accessor :default_channel, :default_username, :default_icon_emoji, :webhook_url
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
76
|
+
def initialize
|
77
|
+
@default_channel = ENV["SLACK_DEFAULT_CHANNEL"]
|
78
|
+
@default_username = ENV["SLACK_DEFAULT_USERNAME"]
|
79
|
+
@default_icon_emoji = ENV["SLACK_DEFAULT_ICON_EMOJI"]
|
80
|
+
@webhook_url = ENV["SLACK_WEBHOOK_URL"]
|
81
|
+
end
|
81
82
|
end
|
82
|
-
end
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pubsub_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshiyuki Hirano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -63,15 +63,15 @@ files:
|
|
63
63
|
- Rakefile
|
64
64
|
- lib/generators/pubsub_notifier/install/USAGE
|
65
65
|
- lib/generators/pubsub_notifier/install/install_generator.rb
|
66
|
-
- lib/generators/pubsub_notifier/install/templates/application_notifier.
|
67
|
-
- lib/generators/pubsub_notifier/install/templates/initializer.
|
66
|
+
- lib/generators/pubsub_notifier/install/templates/application_notifier.tt
|
67
|
+
- lib/generators/pubsub_notifier/install/templates/initializer.tt
|
68
68
|
- lib/generators/rails/USAGE
|
69
69
|
- lib/generators/rails/notifier_generator.rb
|
70
|
-
- lib/generators/rails/templates/notifier.
|
70
|
+
- lib/generators/rails/templates/notifier.tt
|
71
71
|
- lib/generators/rspec/notifier_generator.rb
|
72
|
-
- lib/generators/rspec/templates/notifier_spec.
|
72
|
+
- lib/generators/rspec/templates/notifier_spec.tt
|
73
73
|
- lib/generators/test_unit/notifier_generator.rb
|
74
|
-
- lib/generators/test_unit/templates/notifier_test.
|
74
|
+
- lib/generators/test_unit/templates/notifier_test.tt
|
75
75
|
- lib/pubsub_notifier.rb
|
76
76
|
- lib/pubsub_notifier/acts_as_notifier.rb
|
77
77
|
- lib/pubsub_notifier/base.rb
|
@@ -1,10 +0,0 @@
|
|
1
|
-
PubsubNotifier.config.logger = Rails.logger
|
2
|
-
|
3
|
-
require "pubsub_notifier/slack_client"
|
4
|
-
|
5
|
-
PubsubNotifier::SlackClient.configure do |config|
|
6
|
-
config.default_channel = ENV['SLACK_DEFAULT_CHANNEL']
|
7
|
-
config.default_username = ENV['SLACK_DEFAULT_USERNAME']
|
8
|
-
config.default_icon_emoji = ENV['SLACK_DEFAULT_ICON_EMOJI']
|
9
|
-
config.webhook_url = ENV['SLACK_WEBHOOK_URL']
|
10
|
-
end
|