simple_notifications 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1709f0238eda36afb2285dd4e57a53ec62fcf1e80a9f3268d573294ea9fb4e1
4
- data.tar.gz: d75e8e7a639e530bc92907050f365013b7c1901a3a7a6ffd019092d9e95130c9
3
+ metadata.gz: 7feb94255eb57fe400bdd67560d4c9890f2c4866e35c11504005829c12847061
4
+ data.tar.gz: c67598078beefc268de6223face3958f9fd892cab80b7f22d693d59fa55c68ad
5
5
  SHA512:
6
- metadata.gz: ad26e5c56c0678bbe5f6805707783e4d489604d686212fa11c05010689d76fd245563d68026e38a22def0e624d533f185fb5832481274dfb67b88f0ebe7c2431
7
- data.tar.gz: 298446be7bf1586b81636f1c179ca7224d7d64d423459b263f7f64334ccc1cd2e7062ca152ebb9fb406612b2364622cc4dbea3c5fccd3bde179fbe6ab2643ef5
6
+ metadata.gz: 2044a29e6282a2224971b0a7279e46aa610bcc305d92712cc2e6c26861080d7a00840e3a94755942e952550689e6c71c05ac016d7ff6ec8011ebed63d75421ed
7
+ data.tar.gz: 586dbee2f0433389a095b79c17fad7cd0f480b7ae8bd60d390e54df37089255dac0ddfdcd06d6dda29c956afc21a770abf3629b8f209faf8a5ef09684af5e2c7
data/README.md CHANGED
@@ -28,7 +28,7 @@ rails generate simple_notifications:install
28
28
  This will generate two files in your rails project
29
29
 
30
30
  * simple_notifications.rb - An initializer file.
31
- * Migration file - Required for recording notifications.
31
+ * Migration files - Required for recording notifications.
32
32
 
33
33
  Then run
34
34
 
@@ -39,22 +39,21 @@ rails db:migrate
39
39
  Add following line to the model for which notifications functionality is required
40
40
 
41
41
  ```ruby
42
- notify sender: :product_class,
43
- receivers: :variants,
44
- actions: [:follow, :unfollow, :update, :create],
45
- notify_message: :dd_message,
46
- before_notify: :before_notify_method,
47
- after_notify: :after_notify_method,
48
- before_delivered: :before_delivered_method,
49
- after_delivered: :after_delivered_method,
50
- before_read: :before_read_method,
51
- after_read: :after_read_method
42
+ notify sender: :author,
43
+ receivers: :followers,
44
+ actions: [:follow, :unfollow, :update],
45
+ notify_message: :message_method,
46
+ before_notify: :before_notify_method,
47
+ after_notify: :after_notify_method,
48
+ before_delivered: :before_delivered_method,
49
+ after_delivered: :after_delivered_method,
50
+ before_read: :before_read_method,
51
+ after_read: :after_read_method
52
52
  ```
53
53
  Or you can provide ActiveRecord::Base object or ActiveRecord::Relation objects as
54
54
 
55
55
  ```ruby
56
56
  notify sender: :author, receivers: User.all
57
-
58
57
  notify sender: User.first, receivers: [:followers, User.all]
59
58
  ```
60
59
 
@@ -19,7 +19,8 @@ class CreateSimpleNotifications < ActiveRecord::Migration[5.2]
19
19
 
20
20
  add_index(:simple_notifications, [:sender_id, :sender_type])
21
21
  add_index(:simple_notifications, [:entity_id, :entity_type])
22
- add_index(:deliveries, [:sender_id, :sender_type])
22
+ add_index(:deliveries, [:receiver_id, :receiver_type])
23
23
  add_index(:deliveries, :is_delivered)
24
+ add_index(:deliveries, :is_read)
24
25
  end
25
26
  end
@@ -101,11 +101,17 @@ module SimpleNotifications
101
101
  #post.notify(sender: :author, receivers: :followers, message: 'My Custom logic message')
102
102
  #post.create(content: '', notify: false) -> It does not create the notification.
103
103
  def notify(options = {})
104
- raise 'SimpleNotification::SenderReceiverError' unless @@options[:sender] && @@options[:receivers]
105
- @message = options[:message] if options[:message]
106
- notification = notifications.build(entity: self, sender: get_obj(options[:sender]), message: default_message(self, get_obj(options[:sender]), 'created'))
107
- get_obj(options[:receivers]).each {|receiver| notification.deliveries.build(receiver: receiver)}
108
- notification.save
104
+ if notify.present? && !!notify
105
+ raise 'SimpleNotification::SenderReceiverError' unless @@options[:sender] && @@options[:receivers]
106
+ @message = options[:message] if options[:message]
107
+ notification = notifications.build(entity: self, sender: get_obj(options[:sender]), message: default_message(self, get_obj(options[:sender]), 'created'))
108
+ get_obj(options[:receivers]).each {|receiver| notification.deliveries.build(receiver: receiver)}
109
+ notification.save
110
+ end
111
+ end
112
+
113
+ def flush_notifications
114
+ notifications.destroy_all
109
115
  end
110
116
 
111
117
  # Check if notifications has already been delivered.
@@ -1,3 +1,3 @@
1
1
  module SimpleNotifications
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ashish Garg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-18 00:00:00.000000000 Z
11
+ date: 2018-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler