notifly 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/lib/notifly/models/flyable.rb +17 -6
- data/lib/notifly/models/options/fly.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6111c9569a44311f1348d13fe80f7a8463feae4a
|
4
|
+
data.tar.gz: 65b36c5d13eb9d42d2cb8a628f39d25361d7c306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09d4e63529826842d329b5663951e99b21748a8ab15785e0544610baea5d435889e9752db0d5bfedb03f4894e9b85ea5d5979a401bc410de3924ceb4d7e40b24
|
7
|
+
data.tar.gz: 78e93dcbb853a7afbaf79b6d6973f157b875e77945f9b7d4e40f13b1522e52e78a15d083dbbc51134bf50b805c82287d912aff2827937666353fb0c7f9de8ccb
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ In actual version, notifications are composed by:
|
|
16
16
|
- Read: flag that records if the receiver read the notification
|
17
17
|
- Seen: flag that records if the receiver seen the notification
|
18
18
|
- If and Unless: used to create notifications conditionally
|
19
|
-
-
|
19
|
+
- Kind: an attribute to scope notifications
|
20
20
|
|
21
21
|
|
22
22
|
# Install
|
@@ -65,7 +65,8 @@ class TicketOrder < ActiveRecord::Base
|
|
65
65
|
notifly before: :destroy, template: :destroy, sender: :buyer, data: :attributes
|
66
66
|
notifly after: :send_gift!, template: :ticket_gift, sender: :buyer,
|
67
67
|
target: :ticket, if: -> { completed? }
|
68
|
-
notifly after: :accept_gift, sender:
|
68
|
+
notifly after: :accept_gift, sender: -> { self.owner }, receiver: :buyer, target: :ticket,
|
69
|
+
then: ->(notification) { self.send_mail_with(notification) }
|
69
70
|
|
70
71
|
def send_gift!
|
71
72
|
# code here
|
@@ -74,6 +75,10 @@ class TicketOrder < ActiveRecord::Base
|
|
74
75
|
def accept_gift
|
75
76
|
# code here
|
76
77
|
end
|
78
|
+
|
79
|
+
def send_mail_with(notification)
|
80
|
+
# code here
|
81
|
+
end
|
77
82
|
end
|
78
83
|
```
|
79
84
|
Value explanation about each parameter:
|
@@ -86,6 +91,8 @@ Value explanation about each parameter:
|
|
86
91
|
| `template` | The symbol or string that indicates which partial will be rendered at views. The partial must be inside `app/views/notifly/templates/`. Default is `:default`. |
|
87
92
|
| `target` | The method which returns the notification target object. It's a third actor of the notification. Example: In "Max sent you a ticket" notification, Max is the sender, you are the receiver and the **ticket is the target**. |
|
88
93
|
| `data` | A method which returns a hash with usefull values to be persisted, like ticket price or whatever you want to persist. |
|
94
|
+
| `kind` | String used to scope notifications, default is `:notification` and all notifications with default type will be shown in `current_user`'s notifications
|
95
|
+
| `then` | Callback that will be executed **after** the notification creation. It can receive a notification as parameter. Right now it only works in the code above.
|
89
96
|
|
90
97
|
Note that you can use the `default_values` parameter, it is specific to DRY your
|
91
98
|
notiflies and set the values to all notiflies. If you need to overwrite some
|
@@ -91,17 +91,14 @@ module Notifly
|
|
91
91
|
|
92
92
|
def _create_notification_for(fly)
|
93
93
|
new_fly = _default_fly.merge(fly)
|
94
|
-
notification = Notifly::Notification.create _get_attributes_from(new_fly)
|
95
94
|
|
96
|
-
|
97
|
-
|
95
|
+
notification = Notifly::Notification.create _get_attributes_from(new_fly)
|
96
|
+
_after_create_notification(notification, new_fly)
|
98
97
|
|
99
|
-
Notifly::NotificationMailer.notifly to: self.email, template: template,
|
100
|
-
notification_id: notification.id
|
101
|
-
end
|
102
98
|
rescue => e
|
103
99
|
logger.error "Something goes wrong with Notifly, will ignore: #{e}"
|
104
100
|
raise e if not Rails.env.production?
|
101
|
+
|
105
102
|
end
|
106
103
|
|
107
104
|
def notifly_notifications(kind=nil)
|
@@ -137,6 +134,20 @@ module Notifly
|
|
137
134
|
end
|
138
135
|
end
|
139
136
|
end
|
137
|
+
|
138
|
+
def _after_create_notification(notification, fly)
|
139
|
+
if fly.then.present?
|
140
|
+
block = fly.then;
|
141
|
+
block.parameters.present? ? instance_exec(notification, &block) : instance_exec(&block)
|
142
|
+
end
|
143
|
+
|
144
|
+
if fly.mail.present?
|
145
|
+
template = fly.mail.try(:fetch, :template) || notification.template
|
146
|
+
|
147
|
+
Notifly::NotificationMailer.notifly to: self.email, template: template,
|
148
|
+
notification_id: notification.id
|
149
|
+
end
|
150
|
+
end
|
140
151
|
end
|
141
152
|
end
|
142
153
|
end
|
@@ -3,7 +3,7 @@ module Notifly
|
|
3
3
|
module Options
|
4
4
|
class Fly
|
5
5
|
attr_accessor :before, :after, :template, :sender, :receiver, :target,
|
6
|
-
:if, :unless, :data, :mail, :kind
|
6
|
+
:if, :unless, :data, :mail, :kind, :then
|
7
7
|
|
8
8
|
def initialize(options={})
|
9
9
|
options = options.fetch(:default_values, options)
|
@@ -23,7 +23,7 @@ module Notifly
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def attributes
|
26
|
-
no_attrs = [hook, :if, :unless, :mail]
|
26
|
+
no_attrs = [hook, :if, :unless, :mail, :then]
|
27
27
|
attrs = instance_values.reject { |key| no_attrs.include? key.to_sym }
|
28
28
|
attrs.merge({mail: get_mail_type})
|
29
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Passalini
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-12-
|
12
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|