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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7afc8a84729f47928bca7b4b3b432ceba1d98458
4
- data.tar.gz: 10c9907f794ebd014e0dbe372b386ca6008f08e6
3
+ metadata.gz: bbf75609870b5f43818cd6ca1c2b320bbf1ad2fe
4
+ data.tar.gz: 7ead5b1b9bfe7e0f432bd7267277b38bba21393f
5
5
  SHA512:
6
- metadata.gz: 4e770a775b9e7f04cb9f59cefb02e845f06dbd2018f199841a35bdb43dd55f11bd2c08c30129a80fe351ac04c7e8c4d754d3e924780999cbd427fc912066b077
7
- data.tar.gz: '03547309641d77529300b6b9d3116ba7b924beef44fd9457de49ff50234452fa235f4e6e36005cf4aaab11ab498c14a095b37edb019d63903e2a39c9fc809de2'
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
- class InstallGenerator < ::Rails::Generators::Base
3
- source_root File.expand_path("../templates", __FILE__)
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
4
5
 
5
- def create_initializer_file
6
- template "initializer.rb", "config/initializers/pubsub_notifier.rb"
7
- end
6
+ def create_initializer_file
7
+ template "initializer.tt", "config/initializers/pubsub_notifier.rb"
8
+ end
8
9
 
9
- def create_application_notifier_file
10
- template "application_notifier.rb", "app/notifiers/application_notifier.rb"
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
@@ -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 < ::Rails::Generators::NamedBase
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 'notifier.rb', File.join('app/notifiers', class_path, "#{file_name}_notifier.rb")
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
- record = recipient
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
- record = recipient
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
- class NotifierGenerator < ::Rails::Generators::NamedBase
3
- source_root File.expand_path("../templates", __FILE__)
2
+ module Generators
3
+ class NotifierGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path("../templates", __FILE__)
4
5
 
5
- def create_spec_file
6
- template 'notifier_spec.rb', File.join('spec/notifiers', class_path, "#{file_name}_notifier_spec.rb")
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
@@ -0,0 +1,5 @@
1
+ require '<%= File.exists?('spec/rails_helper.rb') ? 'rails_helper' : 'spec_helper' %>'
2
+
3
+ RSpec.describe <%= class_name %>Notifier do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -1,9 +1,11 @@
1
1
  module TestUnit
2
- class NotifierGenerator < ::Rails::Generators::NamedBase
3
- source_root File.expand_path("../templates", __FILE__)
2
+ module Generators
3
+ class NotifierGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path("../templates", __FILE__)
4
5
 
5
- def create_spec_file
6
- template 'notifier_test.rb', File.join('test/notifiers', class_path, "#{file_name}_notifier_test.rb")
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
@@ -0,0 +1,6 @@
1
+ require 'test_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= class_name %>NotifierTest < ActiveSupport::TestCase
5
+ end
6
+ <% 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
- # Override ActionMailer::Base#method_missing
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
@@ -2,7 +2,7 @@ module PubsubNotifier
2
2
  class Base
3
3
  class << self
4
4
  def use(name, options = {})
5
- @_client = ( clients[name.to_sym] || clients[:logger] ).new(options)
5
+ @_client = (clients[name.to_sym] || clients[:logger]).new(options)
6
6
  end
7
7
 
8
8
  def client
@@ -19,12 +19,12 @@ module PubsubNotifier
19
19
  { wait: nil, wait_until: nil, queue: :default }
20
20
  end
21
21
 
22
- class BroadcastJob < ::ActiveJob::Base
23
- def perform(subscriber_name, event, args)
24
- subscriber = subscriber_name.constantize
25
- subscriber.public_send(event, *args)
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
@@ -9,7 +9,8 @@ module PubsubNotifier
9
9
  @_config ||= self::Config.new
10
10
  end
11
11
 
12
- def initialize(options = {}); end
12
+ def initialize(options = {})
13
+ end
13
14
 
14
15
  def notify_success(message)
15
16
  raise NotImplementedError, "#{self.class}##{__method__} is not implemented"
@@ -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 = ( options.delete(:async) ? broadcasters[:async] : nil ) || broadcasters[:default]
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
- alias pubilish broadcast
30
+ alias_method :pubilish, :broadcast
31
31
 
32
32
  private
33
33
 
@@ -1,6 +1,6 @@
1
- require 'net/http'
2
- require 'json'
3
- require 'uri'
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: 'good',
20
- mrkdwn_in: ['text'],
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: 'danger',
30
- mrkdwn_in: ['text'],
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
- class Config
74
- attr_accessor :default_channel, :default_username, :default_icon_emoji, :webhook_url
73
+ class Config
74
+ attr_accessor :default_channel, :default_username, :default_icon_emoji, :webhook_url
75
75
 
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']
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
 
@@ -1,3 +1,3 @@
1
1
  module PubsubNotifier
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.1".freeze
3
3
  end
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.0
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-13 00:00:00.000000000 Z
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.rb
67
- - lib/generators/pubsub_notifier/install/templates/initializer.rb
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.rb
70
+ - lib/generators/rails/templates/notifier.tt
71
71
  - lib/generators/rspec/notifier_generator.rb
72
- - lib/generators/rspec/templates/notifier_spec.rb
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.rb
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
@@ -1,5 +0,0 @@
1
- require '<%= File.exists?('spec/rails_helper.rb') ? 'rails_helper' : 'spec_helper' %>'
2
-
3
- describe <%= class_name %>Notifier do
4
- subject { <%= class_name %>Notifier.new }
5
- end
@@ -1,11 +0,0 @@
1
- require 'test_helper'
2
-
3
- class <%= singular_name.camelize %>NotifierTest < ActiveSupport::TestCase
4
- def setup
5
- @<%= singular_name %> = <%= class_name %>Notifier.new
6
- end
7
-
8
- # test "the truth" do
9
- # assert true
10
- # end
11
- end