mailboxer 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +10 -11
- data/app/mailers/message_mailer.rb +2 -2
- data/app/mailers/notification_mailer.rb +1 -1
- data/app/models/message.rb +3 -2
- data/app/models/notification.rb +3 -2
- data/lib/generators/mailboxer/templates/initializer.rb +1 -2
- data/lib/mailboxer.rb +1 -3
- data/lib/mailboxer/models/messageable.rb +3 -9
- data/mailboxer.gemspec +1 -1
- data/spec/dummy/app/models/cylon.rb +2 -3
- data/spec/dummy/app/models/duck.rb +3 -4
- data/spec/dummy/app/models/user.rb +3 -0
- metadata +5 -5
data/README.textile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
h1. Mailboxer "!https://secure.travis-ci.org/ging/mailboxer.png!":http://travis-ci.org/ging/mailboxer
|
1
|
+
h1. Mailboxer 0.5.x "!https://secure.travis-ci.org/ging/mailboxer.png!":http://travis-ci.org/ging/mailboxer
|
2
2
|
|
3
3
|
This project is based on the need of a private message system for "ging / social_stream":https://github.com/ging/social_stream. Instead of creating our core message system heavily dependent on our development we are trying to implement a generic and potent messaging gem.
|
4
4
|
|
@@ -37,29 +37,28 @@ We are now adding support for sending emails when a Notification or a Message is
|
|
37
37
|
def name
|
38
38
|
return "You should add method :name in your Messageable model"
|
39
39
|
end
|
40
|
-
#Returning the email address of the model
|
41
|
-
|
40
|
+
#Returning the email address of the model if an email should be sent for this object (Message or Notification).
|
41
|
+
#If no mail has to be sent, return nil.
|
42
|
+
def mailboxer_email(object)
|
43
|
+
#Check if an email should be sent for that object
|
44
|
+
#if true
|
42
45
|
return "define_email@on_your.model"
|
43
|
-
|
44
|
-
|
45
|
-
def should_email?(object)
|
46
|
-
return true
|
46
|
+
#if false
|
47
|
+
#return nil
|
47
48
|
end
|
48
49
|
</code></pre>
|
49
50
|
These names are explicit enough to avoid colliding with other methods, but as long as you need to change them you can do it by using mailboxer initializer. Just add or uncomment the following lines:
|
50
51
|
<pre><code>
|
51
52
|
#Configures the methods needed by mailboxer
|
52
|
-
config.email_method = :
|
53
|
+
config.email_method = :mailboxer_email
|
53
54
|
config.name_method = :name
|
54
|
-
config.should_email_method = :should_email?
|
55
55
|
</code></pre>
|
56
56
|
You may change whatever you want or need. For example:
|
57
57
|
<pre><code>
|
58
58
|
config.email_method = :notifications_email
|
59
59
|
config.name_method = :display_name
|
60
|
-
config.should_email_method = :do_you_want_this_to_be_mailed?
|
61
60
|
</code></pre>
|
62
|
-
Will use the method @notification_email@ instead of @
|
61
|
+
Will use the method @notification_email(object)@ instead of @mailboxer_email(object)@ and @display_name@ for @name@
|
63
62
|
|
64
63
|
Using default or custom method names, if your model doesn't implement them, Mailboxer will use dummy methods not to crash but notify you the missing methods.
|
65
64
|
|
@@ -19,7 +19,7 @@ class MessageMailer < ActionMailer::Base
|
|
19
19
|
@receiver = receiver
|
20
20
|
subject = message.subject.to_s
|
21
21
|
subject = strip_tags(subject) unless subject.html_safe?
|
22
|
-
mail(:to => receiver.send(Mailboxer.email_method), :subject => t('mailboxer.message_mailer.subject_new', :subject => subject)) do |format|
|
22
|
+
mail(:to => receiver.send(Mailboxer.email_method,message), :subject => t('mailboxer.message_mailer.subject_new', :subject => subject)) do |format|
|
23
23
|
format.text {render __method__}
|
24
24
|
format.html {render __method__}
|
25
25
|
end
|
@@ -31,7 +31,7 @@ class MessageMailer < ActionMailer::Base
|
|
31
31
|
@receiver = receiver
|
32
32
|
subject = message.subject.to_s
|
33
33
|
subject = strip_tags(subject) unless subject.html_safe?
|
34
|
-
mail(:to => receiver.send(Mailboxer.email_method), :subject => t('mailboxer.message_mailer.subject_reply', :subject => subject)) do |format|
|
34
|
+
mail(:to => receiver.send(Mailboxer.email_method,message), :subject => t('mailboxer.message_mailer.subject_reply', :subject => subject)) do |format|
|
35
35
|
format.text {render __method__}
|
36
36
|
format.html {render __method__}
|
37
37
|
end
|
@@ -14,7 +14,7 @@ class NotificationMailer < ActionMailer::Base
|
|
14
14
|
@receiver = receiver
|
15
15
|
subject = notification.subject.to_s
|
16
16
|
subject = strip_tags(subject) unless subject.html_safe?
|
17
|
-
mail(:to => receiver.send(Mailboxer.email_method), :subject => t('mailboxer.notification_mailer.subject', :subject => subject)) do |format|
|
17
|
+
mail(:to => receiver.send(Mailboxer.email_method,notification), :subject => t('mailboxer.notification_mailer.subject', :subject => subject)) do |format|
|
18
18
|
format.text {render __method__}
|
19
19
|
format.html {render __method__}
|
20
20
|
end
|
data/app/models/message.rb
CHANGED
@@ -42,8 +42,9 @@ class Message < Notification
|
|
42
42
|
temp_receipts.each(&:save!) #Save receipts
|
43
43
|
self.recipients.each do |r|
|
44
44
|
#Should send an email?
|
45
|
-
if Mailboxer.uses_emails
|
46
|
-
|
45
|
+
if Mailboxer.uses_emails
|
46
|
+
email_to = r.send(Mailboxer.email_method,self)
|
47
|
+
unless email_to.blank?
|
47
48
|
MessageMailer.send_email(self,r).deliver
|
48
49
|
end
|
49
50
|
end
|
data/app/models/notification.rb
CHANGED
@@ -48,8 +48,9 @@ class Notification < ActiveRecord::Base
|
|
48
48
|
temp_receipts.each(&:save!) #Save receipts
|
49
49
|
self.recipients.each do |r|
|
50
50
|
#Should send an email?
|
51
|
-
if Mailboxer.uses_emails
|
52
|
-
|
51
|
+
if Mailboxer.uses_emails
|
52
|
+
email_to = r.send(Mailboxer.email_method,self)
|
53
|
+
unless email_to.blank?
|
53
54
|
NotificationMailer.send_email(self,r).deliver
|
54
55
|
end
|
55
56
|
end
|
@@ -7,7 +7,6 @@ Mailboxer.setup do |config|
|
|
7
7
|
config.default_from = "no-reply@mailboxer.com"
|
8
8
|
|
9
9
|
#Configures the methods needed by mailboxer
|
10
|
-
#config.email_method = :
|
10
|
+
#config.email_method = :mailboxer_email
|
11
11
|
#config.name_method = :name
|
12
|
-
#config.should_email_method = :should_email?
|
13
12
|
end
|
data/lib/mailboxer.rb
CHANGED
@@ -6,11 +6,9 @@ module Mailboxer
|
|
6
6
|
mattr_accessor :default_from
|
7
7
|
mattr_accessor :uses_emails
|
8
8
|
mattr_accessor :email_method
|
9
|
-
@@email_method = :
|
9
|
+
@@email_method = :mailboxer_email
|
10
10
|
mattr_accessor :name_method
|
11
11
|
@@name_method = :name
|
12
|
-
mattr_accessor :should_email_method
|
13
|
-
@@should_email_method = :should_email?
|
14
12
|
|
15
13
|
class << self
|
16
14
|
def setup
|
@@ -25,19 +25,13 @@ module Mailboxer
|
|
25
25
|
return "You should add method :name in your Messageable model"
|
26
26
|
end
|
27
27
|
|
28
|
-
#Returning the email address of the model
|
29
|
-
|
28
|
+
#Returning the email address of the model if an email should be sent for this object (Message or Notification).
|
29
|
+
#If no mail has to be sent, return nil.
|
30
|
+
def #{Mailboxer.email_method}(object)
|
30
31
|
super
|
31
32
|
rescue NameError
|
32
33
|
return "define_email@on_your.model"
|
33
34
|
end
|
34
|
-
|
35
|
-
#Returning whether an email should be sent for this object (Message or Notification)
|
36
|
-
def #{Mailboxer.should_email_method}(object)
|
37
|
-
super
|
38
|
-
rescue NameError
|
39
|
-
return true
|
40
|
-
end
|
41
35
|
EOM
|
42
36
|
#Gets the mailbox of the messageable
|
43
37
|
def mailbox
|
data/mailboxer.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "mailboxer"
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.5.0"
|
4
4
|
s.authors = ["Eduardo Casanova Cuesta"]
|
5
5
|
s.summary = "Messaging system for rails apps."
|
6
6
|
s.description = "A Rails engine that allows any model to act as messageable, allowing it to exchange messages " +
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailboxer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eduardo Casanova Cuesta
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-27 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|