notification-handler 1.0.0.beta8 → 1.0.0.beta9

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: 0a4c180ed64ec555efdd26415ce61364a09ac48e81d3d78dfa7d387a2c0f2ad0
4
- data.tar.gz: 89c348007a44edc1e34864973f33e50709fd0b49a3366cb4367221bb7b79d8fc
3
+ metadata.gz: 3fe2fe2c91eabaaec753df7ba65e183a7050eea1270f45c5a3066e535e0ae1b3
4
+ data.tar.gz: dd8f5a2801afa7cc2b8e9d2f372398151c94f6c4139210bf846a63beea89944e
5
5
  SHA512:
6
- metadata.gz: f085d5ef3833c88e265517146e28b92ac8a696a1902dbecb788aab3817751d95232e45e2dc623cad93d29d2d1817ec9962d65058f37214b1f01457a3569ba2af
7
- data.tar.gz: af4e1b23a0843363710ea8937bd6cf69fa9d8e28a63f136d94b38ab3094aaaac184af97185ba0a0f21a99e92b1fe4bc29c1e8c641ba60507a3207be4a40f53e8
6
+ metadata.gz: ed9de05b283ff004cd5b3dda16287cfc4e516a44d65457146025b93c92b4d1993791a45c92f138133e77f4c436e19d5f73eb52af23c948b3b140726998f9679d
7
+ data.tar.gz: 69cbc0114a5b412ef7eec404829080deb34999eda805ac0ea8fab5a8450aad31145e167ae6aa0a5dfa1396ec297ef898e459704cbb663ea184a9b523475d3611
@@ -1,2 +1,6 @@
1
- class Notification < NotificationHandler::Notification
1
+ class Notification < ApplicationRecord
2
+
3
+ include NotificationHandler::NotificationLibrary
4
+ include NotificationHandler::NotificationScopes
5
+
2
6
  end
@@ -2,8 +2,6 @@ module NotificationHandler
2
2
 
3
3
  require 'notification_handler/configuration'
4
4
 
5
- require 'notification_handler/engine'
6
-
7
5
  autoload :Group, 'notification_handler/group'
8
6
 
9
7
  autoload :Target, 'notification_handler/target'
@@ -18,7 +18,7 @@ module NotificationHandler
18
18
  end
19
19
 
20
20
  def define_group name, target_scope
21
- ::NotificationHandler::Group.new name: name.to_sym, target_scope: target_scope
21
+ ::NotificationHandler::Group.new name.to_sym, target_scope
22
22
  end
23
23
 
24
24
  end
@@ -1,39 +1,57 @@
1
1
  module NotificationHandler
2
2
  module NotificationLibrary
3
3
 
4
- attr_accessor :group
4
+ extend ActiveSupport::Concern
5
5
 
6
- before_validation :create_for_group
7
- after_commit :cache
6
+ included do
7
+ before_validation :create_for_group
8
+ after_commit :cache
8
9
 
9
- def read?
10
- self.read
11
- end
12
- def unread?
13
- !self.read
10
+ serialize :metadata, Hash
11
+ attr_accessor :group
12
+
13
+ belongs_to :target, polymorphic: true
14
+ belongs_to :object, polymorphic: true, optional: true
15
+
16
+ include NotificationHandler::NotificationLibrary::InstanceMethods
17
+
18
+ include NotificationRenderer::NotificationLibrary if defined?(NotificationRenderer)
19
+ include NotificationPusher::NotificationLibrary if defined?(NotificationPusher)
20
+ include NotificationSettings::NotificationLibrary if defined?(NotificationSettings)
14
21
  end
15
22
 
16
- private
23
+ module InstanceMethods
17
24
 
18
- def create_for_group
19
- unless self.group.nil?
20
- target_scope = NotificationHandler::Group.find_by_name(self.group).last.target_scope
21
- target_scope&.each do |target|
22
- notification = self.dup
23
- notification.target = target
24
- notification.group = nil
25
- notification.save
25
+ def read?
26
+ self.read
27
+ end
28
+ def unread?
29
+ !self.read
30
+ end
31
+
32
+ private
33
+
34
+ def create_for_group
35
+ unless self.group.nil?
36
+ target_scope = NotificationHandler::Group.find_by_name(self.group).last.target_scope
37
+ target_scope&.each do |target|
38
+ notification = self.dup
39
+ notification.target = target
40
+ notification.group = nil
41
+ notification.save
42
+ end
43
+ return false
26
44
  end
27
- return false
28
45
  end
29
- end
30
46
 
31
- def cache
32
- if self.read_changed?
33
- self.target.read_notification_count = self.target.notifications.read.count
34
- self.target.unread_notification_count = self.target.notifications.unread.count
35
- self.target.save!
47
+ def cache
48
+ if self.read_changed?
49
+ self.target.read_notification_count = self.target.notifications.read.count
50
+ self.target.unread_notification_count = self.target.notifications.unread.count
51
+ self.target.save!
52
+ end
36
53
  end
54
+
37
55
  end
38
56
 
39
57
  end
@@ -1,8 +1,15 @@
1
1
  module NotificationHandler
2
2
  module NotificationScopes
3
3
 
4
- scope :read, -> { where(read: true) }
5
- scope :unread, -> { where(read: false) }
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ scope :read, -> { where(read: true) }
8
+ scope :unread, -> { where(read: false) }
9
+
10
+ include NotificationRenderer::NotificationScopes if defined?(NotificationRenderer)
11
+ include NotificationSettings::NotificationScopes if defined?(NotificationSettings)
12
+ end
6
13
 
7
14
  end
8
15
  end
@@ -18,8 +18,7 @@ module NotificationHandler
18
18
  module InstanceMethods
19
19
 
20
20
  def notify options = {}
21
- options[:target] = self
22
- Notification.create options
21
+ self.notifications.create options
23
22
  end
24
23
 
25
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notification-handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta8
4
+ version: 1.0.0.beta9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Hübotter
@@ -82,7 +82,6 @@ files:
82
82
  - lib/generators/templates/install/notifications_migration.rb.erb
83
83
  - lib/notification-handler.rb
84
84
  - lib/notification_handler/configuration.rb
85
- - lib/notification_handler/engine.rb
86
85
  - lib/notification_handler/group.rb
87
86
  - lib/notification_handler/notification_library.rb
88
87
  - lib/notification_handler/notification_scopes.rb
@@ -1,6 +0,0 @@
1
- require 'rails/railtie'
2
-
3
- module NotificationHandler
4
- class Engine < ::Rails::Engine
5
- end
6
- end