gossiper 0.3.8 → 0.5.0

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: 73d578f1c535eaaeb002558c0bc74a6592a8e22a
4
- data.tar.gz: e995e9d05e66af43cb77b139800cdb6beeca455d
3
+ metadata.gz: 7b1840e880a934d5e464bbfb8a29f8f322242ff6
4
+ data.tar.gz: 3b4ad03f0c2dcd0de1f3977b7c22e4e6747d4192
5
5
  SHA512:
6
- metadata.gz: 61111ed23a1ecc731148d0b843a539b98b1df9252f97f464bcc960daaf0e6361b9e3c7087db2e1a4ed86b3dde6489a69444ad745b1962127a16ad1564dace9c2
7
- data.tar.gz: f1352ee94b7709766a79c986888e6d1d97faca01c30fd40da80a7045f416b412b9162b71f12a4e69fc3c1848ca55eacdf591ae9867e4a55d83f36b61ee15ac36
6
+ metadata.gz: 54904a932f3d326ef56a4882a7c296b867e1131b9a5a9d29b02b02afcf14a21e150c11a52a35751a7b5827dcd763f2580e9abacdc2ac0db9bf5c1a426dc5fed4
7
+ data.tar.gz: 02a77e375098867dfee87355f3d8ff9c683983264f2fdc5f49ff93b839a1ec744de3884993591b3318f9ef44a77a18f4099248287958b2c0ea721acee9bfafa2
@@ -10,7 +10,7 @@ module Gossiper
10
10
  end
11
11
 
12
12
  def show
13
- respond_with(notification)
13
+ respond_with(notification, location: :notifications)
14
14
  end
15
15
 
16
16
  def deliver
@@ -17,7 +17,7 @@
17
17
  <% decorator = Gossiper::NotificationDecorator.new(notification) %>
18
18
  <tr>
19
19
  <td><%= decorator.kind %></td>
20
- <td><%= decorator.user.email %></td>
20
+ <td><%= decorator.to %></td>
21
21
  <td><%= decorator.delivered_at %></td>
22
22
  <td><%= decorator.status %></td>
23
23
  <td><%= decorator.read? %></td>
@@ -31,7 +31,7 @@
31
31
  },
32
32
  class: 'btn pull-right'
33
33
  ) %>
34
- <%= link_to(t('.show', default: t('gossiper.notifications.show')), notification, class: 'btn pull-right') %>
34
+ <%= link_to(t('.show', default: t('gossiper.notifications.show')), notification_path(notification), class: 'btn pull-right') %>
35
35
  </td>
36
36
  </tr>
37
37
  <% end %>
@@ -12,7 +12,7 @@
12
12
 
13
13
  <tr>
14
14
  <th class="title"><%= Gossiper::Notification.human_attribute_name('email_body') rescue t("email_body") %></th>
15
- <td><pre><%= decorator.email_object %></pre></td>
15
+ <td><%= decorator.email_object.encoded.html_safe %></td>
16
16
  </tr>
17
17
 
18
18
  </table>
@@ -0,0 +1,5 @@
1
+ class AddTypeToNotifications < ActiveRecord::Migration
2
+ def change
3
+ add_column :notifications, :type, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddToToGossiperNotifications < ActiveRecord::Migration
2
+ def change
3
+ add_column :gossiper_notifications, :to, :text
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ class RemoveKindFromGossiperNotifications < ActiveRecord::Migration
2
+ def up
3
+ remove_column :gossiper_notifications, :kind
4
+ end
5
+
6
+ def down
7
+ add_column :notifications, :type, :string
8
+ end
9
+
10
+ end
@@ -1,8 +1,7 @@
1
1
  module Notifications
2
- class <%= class_name %>Notification < Gossiper::EmailConfig
3
-
4
- # def initialize(notification)
5
- # end
2
+ class <%= class_name %>Notification < Gossiper::Notification
3
+ # uncomment the below line to require user and enable user notifications
4
+ # require_user
6
5
 
7
6
  # def from
8
7
  # end
@@ -21,15 +21,15 @@ module Gossiper
21
21
  end
22
22
 
23
23
  def kind
24
- t("gossiper.notifications.#{notification.kind}.title",
25
- default: notification.kind.titleize
26
- )
24
+ t("gossiper.notifications.#{notification.type.underscore}.title",
25
+ default: notification.type.titleize
26
+ )
27
27
  end
28
28
 
29
29
  def subject
30
- t("gossiper.notifications.#{notification.kind}.subject",
30
+ t("gossiper.notifications.#{notification.type.underscore}.subject",
31
31
  default: kind
32
- )
32
+ )
33
33
  end
34
34
 
35
35
  def status
@@ -41,9 +41,8 @@ module Gossiper
41
41
  end
42
42
 
43
43
  def email
44
- notification.user.email
44
+ notification.to
45
45
  end
46
- alias_method :to, :email
47
46
 
48
47
  def delivered_at
49
48
  decorate_date(notification.delivered_at)
@@ -0,0 +1,64 @@
1
+ module Gossiper
2
+ module Concerns
3
+ module Models
4
+ module EmailSettings
5
+ extend ActiveSupport::Concern
6
+
7
+ def from
8
+ config.default_from
9
+ end
10
+
11
+ def reply_to
12
+ config.default_reply_to.presence || config.default_from
13
+ end
14
+
15
+ def bcc
16
+ config.default_bcc
17
+ end
18
+
19
+ def cc
20
+ config.default_cc
21
+ end
22
+
23
+ def template_name
24
+ type.underscore
25
+ end
26
+
27
+ def template_path
28
+ ''
29
+ end
30
+
31
+ def subject
32
+ I18n.t("gossiper.notifications.#{type.underscore}.subject", subject_variables)
33
+ end
34
+
35
+ def attachments
36
+ {}
37
+ end
38
+
39
+ def instance_variables
40
+ {}
41
+ end
42
+
43
+ def subject_variables
44
+ {}
45
+ end
46
+
47
+ def deliver
48
+ mail.deliver
49
+ update_delivered_at!
50
+ end
51
+
52
+ def deliver!
53
+ mail.deliver!
54
+ update_delivered_at!
55
+ end
56
+
57
+ def config
58
+ Gossiper.configuration
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ end
@@ -7,8 +7,8 @@ module Gossiper
7
7
  STATUSES = %w(pending delivered)
8
8
 
9
9
  included do
10
+ include Gossiper::Concerns::Models::EmailSettings
10
11
  serialize :data, JSON
11
- validates :kind, presence: true
12
12
  belongs_to :user, polymorphic: true
13
13
  end
14
14
 
@@ -20,25 +20,6 @@ module Gossiper
20
20
  read_attribute(:data).presence || {}
21
21
  end
22
22
 
23
- def deliver
24
- mail.deliver
25
- update_delivered_at!
26
- end
27
-
28
- def deliver!
29
- mail.deliver!
30
- update_delivered_at!
31
- end
32
-
33
- def kind=(value)
34
- value = value.present? ? value.parameterize.underscore : nil
35
- write_attribute(:kind, value)
36
- end
37
-
38
- def config
39
- ClassResolver.new.resolve(kind).constantize.new(self)
40
- end
41
-
42
23
  def method_missing(method, *args, &block)
43
24
  STATUSES.each do |status|
44
25
  if method.to_s == "#{status}?"
@@ -48,10 +29,17 @@ module Gossiper
48
29
  super(method, *args, &block)
49
30
  end
50
31
 
51
- protected
52
- def mail
53
- Gossiper::Mailer.mail_for(self)
32
+ module ClassMethods
33
+ def require_user
34
+ include Gossiper::Concerns::Models::UserNotification
54
35
  end
36
+ end
37
+
38
+ def mail
39
+ Gossiper::Mailer.mail_for(self)
40
+ end
41
+
42
+ private
55
43
 
56
44
  def update_delivered_at!
57
45
  self.delivered_at = Time.now
@@ -0,0 +1,24 @@
1
+ module Gossiper
2
+ module Concerns
3
+ module Models
4
+ module UserNotification
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ validates :user, presence: true
9
+ end
10
+
11
+ def to
12
+ if user.present?
13
+ if user.respond_to?(:name) && user.name.present?
14
+ "#{user.name} <#{user.email}>"
15
+ else
16
+ user.email
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -2,14 +2,14 @@ module Gossiper
2
2
  class Mailer < ActionMailer::Base
3
3
 
4
4
  def mail_for(notification)
5
- config = notification.config
5
+ @notification = NotificationDecorator.new(notification)
6
+
7
+ config = notification
6
8
 
7
9
  config.attachments.each do |filename, file|
8
10
  attachments[filename] = file
9
11
  end
10
12
 
11
- @notification = NotificationDecorator.new(notification)
12
-
13
13
  config.instance_variables.each do |name, value|
14
14
  instance_variable_set("@#{name}", value)
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module Gossiper
2
- VERSION = "0.3.8"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/gossiper.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require "gossiper/engine"
2
2
  require "gossiper/concerns/models/notification"
3
+ require "gossiper/concerns/models/user_notification"
4
+ require "gossiper/concerns/models/email_settings"
3
5
  require "gossiper/concerns/decorators/notification"
4
- require "gossiper/email_config"
5
6
  require "gossiper/mailer"
6
7
  require "gossiper/configuration"
7
8
  require "gossiper/notification_decorator"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gossiper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Jacobus
@@ -203,8 +203,11 @@ files:
203
203
  - app/controllers/gossiper/application_controller.rb
204
204
  - config/routes.rb
205
205
  - config/locales/en.bootstrap.yml
206
+ - db/migrate/20140304131816_remove_kind_from_gossiper_notifications.rb
207
+ - db/migrate/20140304111323_add_to_to_gossiper_notifications.rb
206
208
  - db/migrate/20131206162038_create_gossiper_notifications.rb
207
209
  - db/migrate/20131214081503_add_data_to_notifications.rb
210
+ - db/migrate/20140304100755_add_type_to_notifications.rb
208
211
  - lib/generators/gossiper/notification_type/USAGE
209
212
  - lib/generators/gossiper/notification_type/notification_type_generator.rb
210
213
  - lib/generators/gossiper/notification_type/templates/notification_type_spec.rb
@@ -217,10 +220,11 @@ files:
217
220
  - lib/generators/gossiper/install/templates/locale.en.yml
218
221
  - lib/gossiper.rb
219
222
  - lib/tasks/gossiper_tasks.rake
220
- - lib/gossiper/email_config.rb
221
223
  - lib/gossiper/engine.rb
222
224
  - lib/gossiper/concerns/decorators/notification.rb
225
+ - lib/gossiper/concerns/models/email_settings.rb
223
226
  - lib/gossiper/concerns/models/notification.rb
227
+ - lib/gossiper/concerns/models/user_notification.rb
224
228
  - lib/gossiper/mailer.rb
225
229
  - lib/gossiper/class_resolver.rb
226
230
  - lib/gossiper/notification_decorator.rb
@@ -1,63 +0,0 @@
1
- module Gossiper
2
- class EmailConfig
3
- attr_reader :notification, :user
4
-
5
- def initialize(notification)
6
- @notification = notification
7
- @user = notification.user rescue nil
8
- end
9
-
10
- def from
11
- config.default_from
12
- end
13
-
14
- def reply_to
15
- config.default_reply_to.presence || config.default_from
16
- end
17
-
18
- def to
19
- if user.respond_to?(:name)
20
- ["#{user.name} <#{user.email}>"]
21
- else
22
- [user.email]
23
- end
24
- end
25
-
26
- def bcc
27
- config.default_bcc
28
- end
29
-
30
- def cc
31
- config.default_cc
32
- end
33
-
34
- def template_name
35
- "#{notification.kind}_notification"
36
- end
37
-
38
- def template_path
39
- 'notifications'
40
- end
41
-
42
- def subject
43
- I18n.t("gossiper.notifications.#{notification.kind}.subject", subject_variables)
44
- end
45
-
46
- def attachments
47
- {}
48
- end
49
-
50
- def instance_variables
51
- {}
52
- end
53
-
54
- def subject_variables
55
- {}
56
- end
57
-
58
- private
59
- def config
60
- Gossiper.configuration
61
- end
62
- end
63
- end