unotifier 0.2.2 → 0.2.3

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
  SHA256:
3
- metadata.gz: 7e36c94a2ad43b15907fd815bdd1cbcf1ac57ccbaa74669a0679c047cad57cd7
4
- data.tar.gz: 1f8b421d296c6cecd822a0dffa3570d7da90258e01ba1e8d17d8a01575c3a40e
3
+ metadata.gz: b8d0d6e9fbcd78989dedfe9692b6995501e6dda0dccfc46c01e8a0d013a568d4
4
+ data.tar.gz: bda785e4df5defce86a8741753825b5cfe2d0c8e0bfcdd1025fcb245892f74d9
5
5
  SHA512:
6
- metadata.gz: 849372e46b95eabf123e16a3be07a61b9b99842defaad61779294df947a89a09ee57b902efe1aab3f1af6e7d6a2b35a8251b25808b517de3cd56639db2ec8ab5
7
- data.tar.gz: cac003f129456229908890a3bb42e8a0b29910ad7e2f36933c8ff64997d8c09fc9ff6170103f8c20da5944d56328879fe8b723966181a737179dc8b982bca399
6
+ metadata.gz: 82eaf6528bd654344a4927624d694a824f1e2832a0a251b5e760d8a3f38bcafdab6978c18405499a8994c78a7defbfda64986105d45e8843a33f3594edd31a4a
7
+ data.tar.gz: 4f0d4e2f18c0d501334cc046fd501d4588e7dcf1578f44c5b8a11ae4232aeb89d14faf1381cf291e3eecd11798f293b6a17e1a2472498638a7391c1c9b7f0ed6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unotifier (0.2.2)
4
+ unotifier (0.2.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,10 +1,11 @@
1
1
  module UNotifier
2
2
  module Provider
3
- class ActionCable
3
+ class ActionCable < ProviderBase
4
4
  attr_reader :server
5
5
  attr_accessor :autohide_delay, :channel_name
6
6
 
7
- def initialize(server, channel_name: nil, autohide_delay: 30)
7
+ def initialize(server, channel_name: nil, autohide_delay: 30, notification_conditions: [])
8
+ super(notification_conditions: notification_conditions)
8
9
  @server = server
9
10
  @autohide_delay = autohide_delay
10
11
  @channel_name =
@@ -13,6 +14,7 @@ module UNotifier
13
14
  end
14
15
 
15
16
  def notify(notification)
17
+ return unless can_notify?(notification)
16
18
  if notification.target.online?
17
19
  @server.broadcast @channel_name.call(notification), serialize_notification(notification)
18
20
  end
@@ -1,12 +1,14 @@
1
1
  module UNotifier
2
2
  module Provider
3
- class ActionMailer
4
- def initialize(mailer, sending_method: :new_notification)
3
+ class ActionMailer < ProviderBase
4
+ def initialize(mailer, sending_method: :new_notification, notification_conditions: [])
5
+ super(notification_conditions: notification_conditions)
5
6
  @mailer = mailer
6
7
  @sending_method = sending_method
7
8
  end
8
9
 
9
10
  def notify(notification)
11
+ return unless can_notify?(notification)
10
12
  @mailer.public_send(@sending_method, notification).deliver
11
13
  end
12
14
  end
@@ -0,0 +1,14 @@
1
+ module UNotifier
2
+ module Provider
3
+ class ProviderBase
4
+ def initialize(notification_conditions: [])
5
+ @notification_conditions = notification_conditions
6
+ end
7
+
8
+ def can_notify?(target)
9
+ return true if @notification_conditions.empty?
10
+ @notification_conditions.all? { |c| c.call(target) }
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/provider.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require_relative "provider/provider_base"
1
2
  require_relative "provider/action_cable"
2
3
  require_relative "provider/action_mailer"
3
4
 
@@ -1,3 +1,3 @@
1
1
  module UNotifier
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unotifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Rashev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-02 00:00:00.000000000 Z
11
+ date: 2018-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,6 +120,7 @@ files:
120
120
  - lib/provider.rb
121
121
  - lib/provider/action_cable.rb
122
122
  - lib/provider/action_mailer.rb
123
+ - lib/provider/provider_base.rb
123
124
  - lib/settings.rb
124
125
  - lib/unotifier.rb
125
126
  - lib/unotifier/version.rb