mailboxer 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +6 -0
- data/README.textile +98 -0
- data/app/mailers/message_mailer.rb +4 -4
- data/app/mailers/notification_mailer.rb +2 -2
- data/app/models/notification.rb +10 -4
- data/config/locales/en.yml +7 -0
- data/{spec/dummy/db → db}/migrate/20110511145103_create_mailboxer.rb +0 -0
- data/db/migrate/20110719110700_add_notified_object.rb +17 -0
- data/lib/generators/mailboxer/install_generator.rb +3 -1
- data/lib/mailboxer/models/messageable.rb +3 -3
- data/mailboxer.gemspec +8 -5
- data/{lib/generators/mailboxer/templates/migration.rb → spec/dummy/db/migrate/20110719111119_create_mailboxer.rb} +0 -0
- data/spec/dummy/db/migrate/20110719121059_add_notified_object.rb +17 -0
- data/spec/dummy/db/schema.rb +7 -7
- metadata +15 -12
- data/README.rdoc +0 -80
- data/spec/dummy/Gemfile.lock +0 -18
data/.gitignore
CHANGED
data/README.textile
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
h1. Mailboxer "!https://secure.travis-ci.org/ging/mailboxer.png!":http://travis-ci.org/ging/mailboxer
|
2
|
+
|
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
|
+
|
5
|
+
After looking for a good gem to use we notice the lack of messaging gems and functionality in them. Mailboxer tries to fill this emptiness giving a powerfull and generic message system. It supports the use of conversations with two or more recipients, send notification to a recipient (intended to be used as system notifications "Your picture has new comments", "John Doe has updated its document", etc.), emails the messageable model (if configured to do so). It has a complete use of a @Mailbox@ object for each messageable with @inbox@, @sentbox@ and @trash@.
|
6
|
+
|
7
|
+
The gem is constantly growing and improving its functionality. As it is used with our paralell development "(ging / social_stream)":https://github.com/ging/social_stream we are finding and fixing bugs continously. If you want some functionality not supported yet or marked as TODO, you can create an "issue":https://github.com/ging/mailboxer/issues to ask for it. It will be a great feedback for us, and we will know what you may find useful of the gem.
|
8
|
+
|
9
|
+
Mailboxer was born from the great, but outdated, code from "lpsergi / acts_as_messageable":https://github.com/psergi/acts_as_messageable.
|
10
|
+
|
11
|
+
We are now working to make an exhaustive documentation and some wiki pages in order to make even easier to use the gem at its full potencial. Please, give us some time if you find something missing or "ask for it":https://github.com/ging/mailboxer/issues.
|
12
|
+
|
13
|
+
h2. Installation
|
14
|
+
|
15
|
+
Add to your Gemfile:
|
16
|
+
<pre><code>
|
17
|
+
gem 'mailboxer'
|
18
|
+
</code></pre>
|
19
|
+
Then run:
|
20
|
+
<pre><code>
|
21
|
+
bundle update
|
22
|
+
</code></pre>
|
23
|
+
Run install script:
|
24
|
+
<pre><code>
|
25
|
+
rails g mailboxer:install
|
26
|
+
</code></pre>
|
27
|
+
And don't forget to migrate you database:
|
28
|
+
<pre><code>
|
29
|
+
rake db:migrate
|
30
|
+
</code></pre>
|
31
|
+
|
32
|
+
h2. Requirements
|
33
|
+
|
34
|
+
We are now adding support for sending emails when a Notification or a Message is sent to one o more recipients. So that, we must assure that Messageable models have some specific methods. These methods are:
|
35
|
+
<pre><code>
|
36
|
+
#Returning any kind of identification you want for the model
|
37
|
+
def name
|
38
|
+
return "You should add method :name in your Messageable model"
|
39
|
+
end
|
40
|
+
#Returning the email address of the model
|
41
|
+
def email
|
42
|
+
return "define_email@on_your.model"
|
43
|
+
end
|
44
|
+
#Returning whether an email should be sent for this object (Message or Notification)
|
45
|
+
def should_email?(object)
|
46
|
+
return true
|
47
|
+
end
|
48
|
+
</code></pre>
|
49
|
+
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
|
+
<pre><code>
|
51
|
+
#Configures the methods needed by mailboxer
|
52
|
+
config.email_method = :email
|
53
|
+
config.name_method = :name
|
54
|
+
config.should_email_method = :should_email?
|
55
|
+
</code></pre>
|
56
|
+
You may change whatever you want or need. For example:
|
57
|
+
<pre><code>
|
58
|
+
config.email_method = :notifications_email
|
59
|
+
config.name_method = :display_name
|
60
|
+
config.should_email_method = :do_you_want_this_to_be_mailed?
|
61
|
+
</code></pre>
|
62
|
+
Will use the method @notification_email@ instead of @email@, @display_name@ for @name@ and @do_you_want_this_to_be_mailed?@ for @should_email?@
|
63
|
+
|
64
|
+
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
|
+
|
66
|
+
h2. Preparing your models
|
67
|
+
|
68
|
+
In your model:
|
69
|
+
<pre><code>
|
70
|
+
class User < ActiveRecord::Base
|
71
|
+
acts_as_messageable
|
72
|
+
end
|
73
|
+
</code></pre>
|
74
|
+
You are not limited to User model. You can use Mailboxer in any other model and use it in serveral different models. If you have ducks and cylons in your application and you want to interchange messages as if they where the same, just use act_as_messageable in each one and you will be able to send duck-duck, duck-cylon, cylon-duck and cylon-cylon messages. Of course, you can extend it for as many clases as you need. Example:
|
75
|
+
<pre><code>
|
76
|
+
class Duck < ActiveRecord::Base
|
77
|
+
acts_as_messageable
|
78
|
+
end
|
79
|
+
</code></pre>
|
80
|
+
<pre><code>
|
81
|
+
class Cylon < ActiveRecord::Base
|
82
|
+
acts_as_messageable
|
83
|
+
end
|
84
|
+
</code></pre>
|
85
|
+
|
86
|
+
h2. Using Mailboxer. API
|
87
|
+
|
88
|
+
In order to mantain the README in a proper size and simplicity, all the API is available in "Mailboxer wiki":https://github.com/ging/mailboxer/wiki
|
89
|
+
|
90
|
+
h2. License
|
91
|
+
|
92
|
+
Copyright (c) 2011 Eduardo Casanova Cuesta
|
93
|
+
|
94
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
95
|
+
|
96
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
97
|
+
|
98
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -19,9 +19,9 @@ 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 =>
|
23
|
-
format.html {render __method__}
|
22
|
+
mail(:to => receiver.send(Mailboxer.email_method), :subject => t('mailboxer.message_mailer.subject_new', :subject => subject)) do |format|
|
24
23
|
format.text {render __method__}
|
24
|
+
format.html {render __method__}
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -31,9 +31,9 @@ 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 =>
|
35
|
-
format.html {render __method__}
|
34
|
+
mail(:to => receiver.send(Mailboxer.email_method), :subject => t('mailboxer.message_mailer.subject_reply', :subject => subject)) do |format|
|
36
35
|
format.text {render __method__}
|
36
|
+
format.html {render __method__}
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -14,9 +14,9 @@ class NotificationMailer < ActionMailer::Base
|
|
14
14
|
@receiver = receiver
|
15
15
|
subject = message.subject.to_s
|
16
16
|
subject = strip_tags(subject) unless subject.html_safe?
|
17
|
-
mail(:to => receiver.send(Mailboxer.email_method), :subject =>
|
18
|
-
format.html {render __method__}
|
17
|
+
mail(:to => receiver.send(Mailboxer.email_method), :subject => t('mailboxer.notification_mailer.subject', :subject => subject)) do |format|
|
19
18
|
format.text {render __method__}
|
19
|
+
format.html {render __method__}
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/app/models/notification.rb
CHANGED
@@ -2,7 +2,7 @@ class Notification < ActiveRecord::Base
|
|
2
2
|
|
3
3
|
attr_accessor :recipients
|
4
4
|
belongs_to :sender, :polymorphic => :true
|
5
|
-
belongs_to :
|
5
|
+
belongs_to :notified_object, :polymorphic => :true
|
6
6
|
validates_presence_of :subject, :body
|
7
7
|
has_many :receipts, :dependent => :destroy
|
8
8
|
|
@@ -10,7 +10,7 @@ class Notification < ActiveRecord::Base
|
|
10
10
|
joins(:receipts).where('receipts.receiver_id' => recipient.id,'receipts.receiver_type' => recipient.class.to_s)
|
11
11
|
}
|
12
12
|
scope :with_object, lambda { |obj|
|
13
|
-
where('
|
13
|
+
where('notified_object_id' => obj.id,'notified_object_type' => obj.class.to_s)
|
14
14
|
}
|
15
15
|
scope :not_trashed, lambda {
|
16
16
|
joins(:receipts).where('receipts.trashed' => false)
|
@@ -21,11 +21,11 @@ class Notification < ActiveRecord::Base
|
|
21
21
|
|
22
22
|
class << self
|
23
23
|
#Sends a Notification to all the recipients
|
24
|
-
def notify_all(recipients,subject,body,
|
24
|
+
def notify_all(recipients,subject,body,obj = nil)
|
25
25
|
notification = Notification.new({:body => body, :subject => subject})
|
26
26
|
notification.recipients = recipients.is_a?(Array) ? recipients : [recipients]
|
27
27
|
notification.recipients = notification.recipients.uniq
|
28
|
-
notification.
|
28
|
+
notification.notified_object = obj if obj.present?
|
29
29
|
return notification.deliver
|
30
30
|
end
|
31
31
|
end
|
@@ -126,5 +126,11 @@ class Notification < ActiveRecord::Base
|
|
126
126
|
end
|
127
127
|
self.body = sanitize self.body
|
128
128
|
end
|
129
|
+
|
130
|
+
#Returns notified_object. DEPRECATED
|
131
|
+
def object
|
132
|
+
warn "DEPRECATION WARNING: use 'notify_object' instead of 'object' to get the object associated with the Notification"
|
133
|
+
notified_object
|
134
|
+
end
|
129
135
|
|
130
136
|
end
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class AddNotifiedObject < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_table :notifications do |t|
|
4
|
+
t.references :notified_object, :polymorphic => true
|
5
|
+
t.remove :object_id
|
6
|
+
t.remove :object_type
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
change_table :notifications do |t|
|
12
|
+
t.remove :notified_object_id
|
13
|
+
t.remove :notified_object_type
|
14
|
+
t.references :object, :polymorphic => true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -14,6 +14,8 @@ class Mailboxer::InstallGenerator < Rails::Generators::Base #:nodoc:
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def create_migration_file
|
17
|
-
|
17
|
+
require 'rake'
|
18
|
+
Rails.application.load_tasks
|
19
|
+
Rake::Task['mailboxer_engine:install:migrations'].invoke
|
18
20
|
end
|
19
21
|
end
|
@@ -18,7 +18,7 @@ module Mailboxer
|
|
18
18
|
|
19
19
|
module InstanceMethods
|
20
20
|
eval <<-EOM
|
21
|
-
#Returning any kind of
|
21
|
+
#Returning any kind of identification you want for the model
|
22
22
|
def #{Mailboxer.name_method}
|
23
23
|
super
|
24
24
|
rescue NameError
|
@@ -47,10 +47,10 @@ module Mailboxer
|
|
47
47
|
end
|
48
48
|
|
49
49
|
#Sends a notification to the messageable
|
50
|
-
def notify(subject,body,
|
50
|
+
def notify(subject,body,obj = nil)
|
51
51
|
notification = Notification.new({:body => body, :subject => subject})
|
52
52
|
notification.recipients = [self]
|
53
|
-
notification.
|
53
|
+
notification.notified_object = obj if obj.present?
|
54
54
|
return notification.deliver
|
55
55
|
end
|
56
56
|
|
data/mailboxer.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "mailboxer"
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.4.0"
|
4
4
|
s.authors = ["Eduardo Casanova Cuesta"]
|
5
5
|
s.summary = "Messaging system for rails apps."
|
6
|
-
s.description = "A Rails engine that allows any model to act as messageable,
|
7
|
-
|
6
|
+
s.description = "A Rails engine that allows any model to act as messageable, allowing it to exchange messages " +
|
7
|
+
"with any other messageable model, even different ones. It supports the use of conversations with " +
|
8
|
+
"two or more recipients to organize the messages. You have a complete use of a mailbox object for " +
|
9
|
+
"each messageable model that manages an inbox, sentbox and trash for conversations. It also supports " +
|
10
|
+
"sending notifications to messageable models, intended to be used as system notifications."
|
8
11
|
s.email = "ecasanovac@gmail.com"
|
9
|
-
s.homepage = "
|
12
|
+
s.homepage = "https://github.com/ging/mailboxer"
|
10
13
|
s.files = `git ls-files`.split("\n")
|
11
14
|
|
12
15
|
# Gem dependencies
|
@@ -16,7 +19,7 @@ Gem::Specification.new do |s|
|
|
16
19
|
|
17
20
|
# Development Gem dependencies
|
18
21
|
#
|
19
|
-
s.add_runtime_dependency('rails', '3.1.0.rc4')
|
22
|
+
s.add_runtime_dependency('rails', '~> 3.1.0.rc4')
|
20
23
|
# Testing database
|
21
24
|
s.add_development_dependency('sqlite3-ruby')
|
22
25
|
# Debugging
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class AddNotifiedObject < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_table :notifications do |t|
|
4
|
+
t.references :notified_object, :polymorphic => true
|
5
|
+
t.remove :object_id
|
6
|
+
t.remove :object_type
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
change_table :notifications do |t|
|
12
|
+
t.remove :notified_object_id
|
13
|
+
t.remove :notified_object_type
|
14
|
+
t.references :object, :polymorphic => true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended to check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(:version =>
|
13
|
+
ActiveRecord::Schema.define(:version => 20110719121059) do
|
14
14
|
|
15
15
|
create_table "conversations", :force => true do |t|
|
16
16
|
t.string "subject", :default => ""
|
@@ -35,15 +35,15 @@ ActiveRecord::Schema.define(:version => 20110511145103) do
|
|
35
35
|
create_table "notifications", :force => true do |t|
|
36
36
|
t.string "type"
|
37
37
|
t.text "body"
|
38
|
-
t.string "subject",
|
38
|
+
t.string "subject", :default => ""
|
39
39
|
t.integer "sender_id"
|
40
40
|
t.string "sender_type"
|
41
|
-
t.integer "object_id"
|
42
|
-
t.string "object_type"
|
43
41
|
t.integer "conversation_id"
|
44
|
-
t.boolean "draft",
|
45
|
-
t.datetime "updated_at",
|
46
|
-
t.datetime "created_at",
|
42
|
+
t.boolean "draft", :default => false
|
43
|
+
t.datetime "updated_at", :null => false
|
44
|
+
t.datetime "created_at", :null => false
|
45
|
+
t.integer "notified_object_id"
|
46
|
+
t.string "notified_object_type"
|
47
47
|
end
|
48
48
|
|
49
49
|
add_index "notifications", ["conversation_id"], :name => "index_notifications_on_conversation_id"
|
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: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.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-20 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
hash: 15424109
|
45
45
|
segments:
|
@@ -146,7 +146,7 @@ dependencies:
|
|
146
146
|
type: :development
|
147
147
|
name: capybara
|
148
148
|
version_requirements: *id008
|
149
|
-
description: A Rails engine that allows any model to act as messageable,
|
149
|
+
description: A Rails engine that allows any model to act as messageable, allowing it to exchange messages with any other messageable model, even different ones. It supports the use of conversations with two or more recipients to organize the messages. You have a complete use of a mailbox object for each messageable model that manages an inbox, sentbox and trash for conversations. It also supports sending notifications to messageable models, intended to be used as system notifications.
|
150
150
|
email: ecasanovac@gmail.com
|
151
151
|
executables: []
|
152
152
|
|
@@ -157,10 +157,11 @@ extra_rdoc_files: []
|
|
157
157
|
files:
|
158
158
|
- .gitignore
|
159
159
|
- .rspec
|
160
|
+
- .travis.yml
|
160
161
|
- .yardopts
|
161
162
|
- Gemfile
|
162
163
|
- LICENSE.txt
|
163
|
-
- README.
|
164
|
+
- README.textile
|
164
165
|
- Rakefile
|
165
166
|
- VERSION
|
166
167
|
- app/mailers/message_mailer.rb
|
@@ -176,15 +177,16 @@ files:
|
|
176
177
|
- app/views/message_mailer/reply_message_email.text.erb
|
177
178
|
- app/views/notification_mailer/new_notification_email.html.erb
|
178
179
|
- app/views/notification_mailer/new_notification_email.text.erb
|
180
|
+
- config/locales/en.yml
|
181
|
+
- db/migrate/20110511145103_create_mailboxer.rb
|
182
|
+
- db/migrate/20110719110700_add_notified_object.rb
|
179
183
|
- lib/generators/mailboxer/install_generator.rb
|
180
184
|
- lib/generators/mailboxer/templates/initializer.rb
|
181
|
-
- lib/generators/mailboxer/templates/migration.rb
|
182
185
|
- lib/mailboxer.rb
|
183
186
|
- lib/mailboxer/engine.rb
|
184
187
|
- lib/mailboxer/models/messageable.rb
|
185
188
|
- mailboxer.gemspec
|
186
189
|
- spec/dummy/Gemfile
|
187
|
-
- spec/dummy/Gemfile.lock
|
188
190
|
- spec/dummy/Rakefile
|
189
191
|
- spec/dummy/app/controllers/application_controller.rb
|
190
192
|
- spec/dummy/app/helpers/application_helper.rb
|
@@ -211,7 +213,8 @@ files:
|
|
211
213
|
- spec/dummy/db/migrate/20110228120600_create_users.rb
|
212
214
|
- spec/dummy/db/migrate/20110306002940_create_ducks.rb
|
213
215
|
- spec/dummy/db/migrate/20110306015107_create_cylons.rb
|
214
|
-
- spec/dummy/db/migrate/
|
216
|
+
- spec/dummy/db/migrate/20110719111119_create_mailboxer.rb
|
217
|
+
- spec/dummy/db/migrate/20110719121059_add_notified_object.rb
|
215
218
|
- spec/dummy/db/schema.rb
|
216
219
|
- spec/dummy/public/404.html
|
217
220
|
- spec/dummy/public/422.html
|
@@ -242,7 +245,7 @@ files:
|
|
242
245
|
- spec/models/receipt_spec.rb
|
243
246
|
- spec/spec_helper.rb
|
244
247
|
has_rdoc: true
|
245
|
-
homepage:
|
248
|
+
homepage: https://github.com/ging/mailboxer
|
246
249
|
licenses: []
|
247
250
|
|
248
251
|
post_install_message:
|
data/README.rdoc
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
= Mailboxer
|
2
|
-
|
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
|
-
|
5
|
-
It is born from the great, but old, code from {lpsergi / acts_as_messageable}[https://github.com/psergi/acts_as_messageable].
|
6
|
-
|
7
|
-
There is a lack of documentaion and it will be solved as soon as the gem is more stable and had proved to be useful integrated with SocialStream.
|
8
|
-
|
9
|
-
|
10
|
-
= Installation
|
11
|
-
|
12
|
-
Add to your Gemfile:
|
13
|
-
|
14
|
-
gem 'mailboxer'
|
15
|
-
|
16
|
-
Then run:
|
17
|
-
|
18
|
-
bundle update
|
19
|
-
|
20
|
-
Run install script:
|
21
|
-
|
22
|
-
rails g mailboxer:install
|
23
|
-
|
24
|
-
And don't forget to migrate you database:
|
25
|
-
|
26
|
-
rake db:migrate
|
27
|
-
|
28
|
-
= Requirements
|
29
|
-
|
30
|
-
We are now adding support for sending emails when a Notification or a Message is sent to one o more recipients. So that, we mus assure that Messageable models have some specific methods. This methods are:
|
31
|
-
|
32
|
-
#Returning any kind of indentification you want for the model
|
33
|
-
def name
|
34
|
-
return "You should add method :name in your Messageable model"
|
35
|
-
end
|
36
|
-
|
37
|
-
#Returning the email address of the model
|
38
|
-
def email
|
39
|
-
return "define_email@on_your.model"
|
40
|
-
end
|
41
|
-
|
42
|
-
#Returning whether an email should be sent for this object (Message or Notification)
|
43
|
-
def should_email?(object)
|
44
|
-
return true
|
45
|
-
end
|
46
|
-
|
47
|
-
These names are explicit enough to not collide with other methods, but as long as you need to change them you can do it by using mailboxer intializer. Just add or uncomment the following lines:
|
48
|
-
|
49
|
-
#Configures the methods needed by mailboxer
|
50
|
-
config.email_method = :email
|
51
|
-
config.name_method = :name
|
52
|
-
config.should_email_method = :should_email?
|
53
|
-
|
54
|
-
You may change to whatever you want or need. For example:
|
55
|
-
|
56
|
-
config.email_method = :notifications_email
|
57
|
-
config.name_method = :display_name
|
58
|
-
config.should_email_method = :do_you_want_this_to_be_mailed?
|
59
|
-
|
60
|
-
Will use the method "notification_email" instead of "email", "display_name" for "name" and "do_you_want_this_to_be_mailed?" for "should_email?"
|
61
|
-
|
62
|
-
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.
|
63
|
-
|
64
|
-
= Usage
|
65
|
-
|
66
|
-
In your model:
|
67
|
-
|
68
|
-
class User < ActiveRecord::Base
|
69
|
-
acts_as_messageable
|
70
|
-
end
|
71
|
-
|
72
|
-
You are not limited to User model. You can use Mailboxer in any other model and use it in serveral different models. If you have ducks and cylons in your application and you want to interchange messages as if they where the same, just use act_as_messageable in each one and you will be able to send duck-duck, duck-cylon, cylon-duck and cylon-cylon messages. Of course, you can extend it for as many clases as you need. Example:
|
73
|
-
|
74
|
-
class Duck < ActiveRecord::Base
|
75
|
-
acts_as_messageable
|
76
|
-
end
|
77
|
-
|
78
|
-
class Cylon < ActiveRecord::Base
|
79
|
-
acts_as_messageable
|
80
|
-
end
|
data/spec/dummy/Gemfile.lock
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ../../../mailboxer
|
3
|
-
specs:
|
4
|
-
mailboxer (0.1.3)
|
5
|
-
foreigner (~> 0.9.1)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: http://rubygems.org/
|
9
|
-
specs:
|
10
|
-
foreigner (0.9.2)
|
11
|
-
mysql (2.8.1)
|
12
|
-
|
13
|
-
PLATFORMS
|
14
|
-
ruby
|
15
|
-
|
16
|
-
DEPENDENCIES
|
17
|
-
mailboxer!
|
18
|
-
mysql (= 2.8.1)
|