mailboxer 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +4 -2
  3. data/Gemfile +2 -2
  4. data/README.md +239 -0
  5. data/Rakefile +1 -21
  6. data/app/models/message.rb +3 -0
  7. data/app/models/receipt.rb +12 -0
  8. data/app/uploaders/attachment_uploader.rb +3 -0
  9. data/lib/generators/mailboxer/install_generator.rb +20 -12
  10. data/lib/generators/mailboxer/templates/add_attachments.rb +13 -0
  11. data/{db/migrate/20110912163911_add_notification_code.rb → lib/generators/mailboxer/templates/add_notification_code.rb} +0 -0
  12. data/{db/migrate/20110719110700_add_notified_object.rb → lib/generators/mailboxer/templates/add_notified_object.rb} +0 -0
  13. data/{db/migrate/20110511145103_create_mailboxer.rb → lib/generators/mailboxer/templates/create_mailboxer.rb} +0 -0
  14. data/lib/generators/mailboxer/templates/initializer.rb +8 -3
  15. data/lib/generators/mailboxer/views_generator.rb +9 -0
  16. data/lib/mailboxer.rb +7 -1
  17. data/lib/mailboxer/engine.rb +2 -0
  18. data/lib/mailboxer/models/messageable.rb +21 -12
  19. data/mailboxer.gemspec +39 -34
  20. data/spec/dummy/.gitignore +4 -0
  21. data/spec/dummy/Gemfile +28 -2
  22. data/spec/dummy/app/controllers/home_controller.rb +4 -0
  23. data/spec/dummy/{public/stylesheets → app/mailers}/.gitkeep +0 -0
  24. data/spec/dummy/app/models/.gitkeep +0 -0
  25. data/spec/dummy/app/models/cylon.rb +1 -0
  26. data/spec/dummy/app/models/user.rb +1 -1
  27. data/spec/dummy/app/views/home/index.html.haml +7 -0
  28. data/spec/dummy/app/views/layouts/application.html.haml +11 -0
  29. data/spec/dummy/config/application.rb +3 -6
  30. data/spec/dummy/config/database.yml +5 -3
  31. data/spec/dummy/config/environments/development.rb +1 -1
  32. data/spec/dummy/config/environments/production.rb +1 -1
  33. data/spec/dummy/config/environments/test.rb +1 -1
  34. data/spec/dummy/config/initializers/mailboxer.rb +7 -2
  35. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  36. data/spec/dummy/config/initializers/session_store.rb +1 -1
  37. data/spec/dummy/config/locales/en.yml +1 -1
  38. data/spec/dummy/config/routes.rb +1 -3
  39. data/spec/dummy/config/sunspot.yml +17 -0
  40. data/spec/dummy/db/migrate/{20110719111119_create_mailboxer.rb → 20120123185900_create_mailboxer.rb} +0 -0
  41. data/spec/dummy/db/migrate/{20110719121059_add_notified_object.rb → 20120123185901_add_notified_object.rb} +0 -0
  42. data/spec/dummy/db/migrate/{20110912170902_add_notification_code.rb → 20120123185902_add_notification_code.rb} +0 -0
  43. data/spec/dummy/db/migrate/20120123185903_add_attachments.rb +13 -0
  44. data/spec/dummy/public/index.html +239 -0
  45. data/spec/dummy/public/robots.txt +5 -0
  46. data/spec/dummy/public/uploads/testfile.txt +1 -0
  47. data/spec/dummy/script/rails +1 -1
  48. data/spec/integration/message_and_receipt_spec.rb +2 -2
  49. data/spec/mailers/message_mailer_spec.rb +1 -1
  50. data/spec/mailers/notification_mailer_spec.rb +2 -2
  51. data/spec/models/conversation_spec.rb +1 -1
  52. data/spec/models/mailbox_spec.rb +1 -1
  53. data/spec/models/mailboxer_models_messageable_spec.rb +6 -2
  54. data/spec/models/message_spec.rb +1 -1
  55. data/spec/models/notification_spec.rb +1 -1
  56. data/spec/models/receipt_spec.rb +1 -1
  57. data/spec/testfile.txt +1 -0
  58. metadata +112 -59
  59. data/README.textile +0 -194
  60. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  61. data/spec/dummy/db/schema.rb +0 -73
  62. data/spec/dummy/public/javascripts/application.js +0 -2
  63. data/spec/dummy/public/javascripts/controls.js +0 -965
  64. data/spec/dummy/public/javascripts/dragdrop.js +0 -974
  65. data/spec/dummy/public/javascripts/effects.js +0 -1123
  66. data/spec/dummy/public/javascripts/prototype.js +0 -6001
  67. data/spec/dummy/public/javascripts/rails.js +0 -191
  68. data/spec/dummy/public/stylesheets/scaffold.css +0 -56
data/.gitignore CHANGED
@@ -3,8 +3,10 @@ log/*.log
3
3
  pkg/
4
4
  spec/dummy/db/*.sqlite3
5
5
  spec/dummy/log/*.log
6
+ spec/dummy/log/*.lck
6
7
  spec/dummy/tmp/
7
8
  spec/dummy/.project
9
+ spec/dummy/solr
8
10
  **.tmp_*
9
11
  Gemfile.lock
10
12
  .idea
@@ -1,6 +1,8 @@
1
+ language: ruby
1
2
  rvm:
2
3
  - 1.8.7
3
4
  - 1.9.2
4
- - rbx
5
+ - 1.9.3
5
6
  - ree
6
-
7
+ - rbx-18mode
8
+ - jruby-18mode
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source "http://rubygems.org"
2
-
3
- gemspec
2
+
3
+ gemspec
@@ -0,0 +1,239 @@
1
+ # Mailboxer 0.6.x [![](https://secure.travis-ci.org/ging/mailboxer.png)](http://travis-ci.org/ging/mailboxer) [![](https://gemnasium.com/ging/mailboxer.png)](https://gemnasium.com/ging/mailboxer)
2
+
3
+ This project is based on the need of a private message system for [ging
4
+ / social\_stream](https://github.com/ging/social_stream). Instead of creating our core message system heavily
5
+ dependent on our development we are trying to implement a generic and
6
+ potent messaging gem.
7
+
8
+ After looking for a good gem to use we notice the lack of messaging gems
9
+ and functionality in them. Mailboxer tries to fill this emptiness giving
10
+ a powerfull and generic message system. It supports the use of
11
+ conversations with two or more recipients, send notification to a
12
+ recipient (intended to be used as system notifications “Your picture has
13
+ new comments”, “John Doe has updated its document”, etc.), emails the
14
+ messageable model (if configured to do so). It has a complete use of a
15
+ `Mailbox` object for each messageable with `inbox`, `sentbox` and
16
+ `trash`.
17
+
18
+ The gem is constantly growing and improving its functionality. As it is
19
+ used with our parallel development [ging / social\_stream](https://github.com/ging/social_stream) we are finding and fixing bugs continously. If you want
20
+ some functionality not supported yet or marked as TODO, you can create
21
+ an [issue](https://github.com/ging/mailboxer/issues) to ask for it. It will be a great feedback for us, and we
22
+ will know what you may find useful of the gem.
23
+
24
+ Mailboxer was born from the great, but outdated, code from [lpsergi /
25
+ acts*as*messageable](https://github.com/psergi/acts_as_messageable).
26
+
27
+ We are now working to make an exhaustive documentation and some wiki
28
+ pages in order to make even easier to use the gem at its full potencial.
29
+ Please, give us some time if you find something missing or [ask for
30
+ it](https://github.com/ging/mailboxer/issues).
31
+
32
+ Installation
33
+ ------------
34
+
35
+ Add to your Gemfile:
36
+
37
+ ````
38
+ gem ‘mailboxer’
39
+ ````
40
+
41
+ Then run:
42
+
43
+ ````
44
+ $ bundle update
45
+ ````
46
+
47
+ Run install script:
48
+
49
+ ````
50
+ $ rails g mailboxer:install
51
+ ````
52
+
53
+ And don't forget to migrate you database:
54
+
55
+ ````
56
+ $ rake db:migrate
57
+ ````
58
+
59
+ ## Requirements & Settings
60
+
61
+ ### Emails
62
+
63
+ We are now adding support for sending emails when a Notification or a Message is sent to one o more recipients. You should modify mailboxer initializer (/config/initializer/mailboxer.rb) to edit this settings.
64
+
65
+ ````ruby
66
+ Mailboxer.setup do |config|
67
+ #Configures if you applications uses or no the email sending for Notifications and Messages
68
+ config.uses_emails = true
69
+ #Configures the default from for the email sent for Messages and Notifications of Mailboxer
70
+ config.default_from = "no-reply@dit.upm.es"
71
+ ...
72
+ end
73
+ ````
74
+
75
+ ### User identities
76
+
77
+ Users must have an identity defined by a `name` and an `email`. We must assure that Messageable models have some specific methods. These methods are:
78
+
79
+ ````ruby
80
+ #Returning any kind of identification you want for the model
81
+ def name
82
+ return "You should add method :name in your Messageable model"
83
+ end
84
+ ````
85
+
86
+ ````ruby
87
+ #Returning the email address of the model if an email should be sent for this object (Message or Notification).
88
+ #If no mail has to be sent, return nil.
89
+ def mailboxer_email(object)
90
+ #Check if an email should be sent for that object
91
+ #if true
92
+ return "define_email@on_your.model"
93
+ #if false
94
+ #return nil
95
+ end
96
+ ````
97
+
98
+ 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 (/config/initializer/mailboxer.rb). Just add or uncomment the following lines:
99
+
100
+ ````ruby
101
+ Mailboxer.setup do |config|
102
+ # ...
103
+ #Configures the methods needed by mailboxer
104
+ config.email_method = :mailboxer_email
105
+ config.name_method = :name
106
+ # ...
107
+ end
108
+ ````
109
+
110
+ You may change whatever you want or need. For example:
111
+
112
+ ````ruby
113
+ config.email_method = :notifications_email
114
+ config.name_method = :display_name
115
+ ````
116
+
117
+ Will use the method `notification_email(object)` instead of `mailboxer_email(object)` and `display_name` for `name`.
118
+
119
+ 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.
120
+
121
+ ## Preparing your models
122
+
123
+ In your model:
124
+
125
+ ````ruby
126
+ class User < ActiveRecord::Base
127
+ acts_as_messageable
128
+ end
129
+ ````
130
+
131
+ 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.
132
+
133
+ Example:
134
+
135
+ ````ruby
136
+ class Duck < ActiveRecord::Base
137
+ acts_as_messageable
138
+ end
139
+ ````
140
+
141
+ ````ruby
142
+ class Cylon < ActiveRecord::Base
143
+ acts_as_messageable
144
+ end
145
+ ````
146
+
147
+ ## Mailboxer API
148
+
149
+ ### How can I send a message?
150
+
151
+ ````ruby
152
+ #alfa wants to send a message to beta
153
+ alfa.send_message(beta, "Body", "subject")
154
+ ````
155
+
156
+ ### How can I reply a message?
157
+
158
+ ````ruby
159
+ #alfa wants to reply to all in a conversation
160
+ #using a receipt
161
+ alfa.reply_to_all(receipt, "Reply body")
162
+ #using a conversation
163
+ alfa.reply_to_conversation(conversation, "Reply body")
164
+ ````
165
+
166
+ ````ruby
167
+ #alfa wants to reply to the sender of a message (and ONLY the sender)
168
+ #using a receipt
169
+ alfa.reply_to_sender(receipt, "Reply body")
170
+ ````
171
+
172
+ ### How can I retrieve my conversations?
173
+
174
+ ````ruby
175
+ #alfa wants to retrieve all his conversations
176
+ alfa.mailbox.conversations
177
+ #A wants to retrieve his inbox
178
+ alfa.mailbox.inbox
179
+ #A wants to retrieve his sent conversations
180
+ alfa.mailbox.sentbox
181
+ #alfa wants to retrieve his trashed conversations
182
+ alfa.mailbox.trash
183
+ ````
184
+
185
+ ### How can I paginate conversations?
186
+
187
+ ````ruby
188
+ #Using Kaminari to paginate the differents sets of conversations
189
+ #Paginating all conversations using :page parameter and 9 per page
190
+ conversations = Kaminari.paginate_array(alfa.mailbox.conversations).page(params[:page]).per(9)
191
+ #Paginating received conversations using :page parameter and 9 per page
192
+ conversations = Kaminari.paginate_array(alfa.mailbox.inbox).page(params[:page]).per(9)
193
+ #Paginating sent conversations using :page parameter and 9 per page
194
+ conversations = Kaminari.paginate_array(alfa.mailbox.sentbox).page(params[:page]).per(9)
195
+ #Paginating trashed conversations using :page parameter and 9 per page
196
+ conversations = Kaminari.paginate_array(alfa.mailbox.trash).page(params[:page]).per(9)
197
+ ````
198
+
199
+ ### How can I read the messages of a conversation?
200
+
201
+ As a messageable, what you receive receipts wich are linked with the message itself. You should retrieve your receipts for the conversation a get the message associated to them.
202
+
203
+ This is done this way because receipts save the information about the relation between messageable and the messages: is it read?, is it trashed?, etc.
204
+
205
+ ````ruby
206
+ #alfa gets the last conversation (chronologically, the first in the inbox)
207
+ conversation = alfa.mailbox.inbox.first
208
+ #alfa gets it receipts chronologically ordered.
209
+ receipts = conversation.receipts_for alfa
210
+ #using the receipts (i.e. in the view)
211
+ receipts.each do |receipt|
212
+ ...
213
+ message = receipt.message
214
+ read = receipt.is_unread? #or message.is_unread?(alfa)
215
+ ...
216
+ end
217
+ ````
218
+
219
+ You can take a look at the full documentation of Mailboxer in [rubydoc.info](http://rubydoc.info/gems/mailboxer/frames).
220
+
221
+ ## I need a GUI!
222
+ Check out the [rails-messaging](https://github.com/frodefi/rails-messaging) project.
223
+
224
+ ## Contributors
225
+ * [Roendal](https://github.com/ging/mailboxer/commits/master?author=Roendal) (Eduardo Casanova)
226
+ * [dickeyxxx](https://github.com/ging/mailboxer/commits/master?author=dickeyxxx) (Jeff Dickey)
227
+ * [tonydewan](https://github.com/ging/mailboxer/commits/master?author=tonydewan) (Tony Dewan)
228
+ * [plentz](https://github.com/ging/mailboxer/commits/master?author=plentz) (Diego Plentz)
229
+ * [laserlemon](https://github.com/ging/mailboxer/commits/master?author=laserlemon) (Steve Richert)
230
+
231
+ ## License
232
+
233
+ Copyright © 2012 Eduardo Casanova Cuesta
234
+
235
+ 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:
236
+
237
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
238
+
239
+ 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.
data/Rakefile CHANGED
@@ -1,27 +1,7 @@
1
- require 'rubygems'
2
- begin
3
- require 'bundler/setup'
4
- require 'bundler'
5
- rescue LoadError
6
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
- end
8
- require 'rake'
9
- require 'rake/rdoctask'
1
+ require "bundler/gem_tasks"
10
2
 
11
3
  require 'rspec/core'
12
4
  require 'rspec/core/rake_task'
13
-
14
5
  RSpec::Core::RakeTask.new(:spec)
15
-
16
6
  task :default => :spec
17
7
 
18
- Rake::RDocTask.new do |rdoc|
19
- rdoc.rdoc_dir = 'rdoc'
20
- rdoc.title = "Mailboxer"
21
- rdoc.options << '--line-numbers' << '--inline-source'
22
- rdoc.rdoc_files.include('README.rdoc')
23
- rdoc.rdoc_files.include('lib/**/*.rb', 'app/**/*.rb')
24
- end
25
-
26
-
27
- Bundler::GemHelper.install_tasks
@@ -8,6 +8,9 @@ class Message < Notification
8
8
  scope :conversation, lambda { |conversation|
9
9
  where(:conversation_id => conversation.id)
10
10
  }
11
+
12
+ mount_uploader :attachment, AttachmentUploader
13
+
11
14
  class << self
12
15
  #Sets the on deliver callback method.
13
16
  def on_deliver(callback_method)
@@ -135,4 +135,16 @@ class Receipt < ActiveRecord::Base
135
135
  end
136
136
  end
137
137
 
138
+ if Mailboxer.search_enabled
139
+ searchable do
140
+ text :subject, :boost => 5 do
141
+ message.subject if message
142
+ end
143
+ text :body do
144
+ message.body if message
145
+ end
146
+ integer :receiver_id
147
+ end
148
+ end
149
+
138
150
  end
@@ -0,0 +1,3 @@
1
+ class AttachmentUploader < CarrierWave::Uploader::Base
2
+ storage :file
3
+ end
@@ -1,21 +1,29 @@
1
1
  class Mailboxer::InstallGenerator < Rails::Generators::Base #:nodoc:
2
2
  include Rails::Generators::Migration
3
-
4
3
  source_root File.expand_path('../templates', __FILE__)
5
-
6
- require 'rails/generators/active_record'
7
-
8
- def self.next_migration_number(dirname)
9
- ActiveRecord::Generators::Base.next_migration_number(dirname)
4
+ require 'rails/generators/migration'
5
+
6
+ def self.next_migration_number path
7
+ unless @prev_migration_nr
8
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
9
+ else
10
+ @prev_migration_nr += 1
11
+ end
12
+ @prev_migration_nr.to_s
10
13
  end
11
-
14
+
12
15
  def create_initializer_file
13
16
  template 'initializer.rb', 'config/initializers/mailboxer.rb'
14
17
  end
15
-
16
- def create_migration_file
17
- require 'rake'
18
- Rails.application.load_tasks
19
- Rake::Task['mailboxer_engine:install:migrations'].invoke
18
+
19
+ def copy_migrations
20
+ migrations = ["create_mailboxer.rb","add_notified_object.rb","add_notification_code.rb","add_attachments.rb"]
21
+ migrations.each do |migration|
22
+ begin
23
+ migration_template migration, "db/migrate/" + migration
24
+ rescue
25
+ puts "Another migration is already named '" + migration + "'. Moving to next one."
26
+ end
27
+ end
20
28
  end
21
29
  end
@@ -0,0 +1,13 @@
1
+ class AddAttachments < ActiveRecord::Migration
2
+ def self.up
3
+ change_table :notifications do |t|
4
+ t.string :attachment, :default => nil
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ change_table :notifications do |t|
10
+ t.remove :attachment
11
+ end
12
+ end
13
+ end
@@ -7,6 +7,11 @@ 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 = :mailboxer_email
11
- #config.name_method = :name
12
- end
10
+ config.email_method = :mailboxer_email
11
+ config.name_method = :name
12
+
13
+ #Configures if you use or not a search engine and wich one are you using
14
+ #Supported enignes: [:solr,:sphinx]
15
+ config.search_enabled = false
16
+ config.search_engine = :solr
17
+ end
@@ -0,0 +1,9 @@
1
+ class Mailboxer::ViewsGenerator < Rails::Generators::Base
2
+ source_root File.expand_path("../../../../app/views", __FILE__)
3
+
4
+ desc "Copy Mailboxer views into your app"
5
+ def copy_views
6
+ directory('message_mailer', 'app/views/message_mailer')
7
+ directory('notification_mailer', 'app/views/notification_mailer')
8
+ end
9
+ end
@@ -4,7 +4,13 @@ module Mailboxer
4
4
  end
5
5
 
6
6
  mattr_accessor :default_from
7
+ @@default_from = "no-reply@mailboxer.com"
7
8
  mattr_accessor :uses_emails
9
+ @@uses_emails = true
10
+ mattr_accessor :search_enabled
11
+ @@search_enabled = false
12
+ mattr_accessor :search_engine
13
+ @@search_engine = :solr
8
14
  mattr_accessor :email_method
9
15
  @@email_method = :mailboxer_email
10
16
  mattr_accessor :name_method
@@ -19,4 +25,4 @@ module Mailboxer
19
25
  end
20
26
  # reopen ActiveRecord and include all the above to make
21
27
  # them available to all our models if they want it
22
- require 'mailboxer/engine'
28
+ require 'mailboxer/engine'
@@ -1,5 +1,7 @@
1
1
  # Database foreign keys
2
2
  require 'foreigner'
3
+ require 'carrierwave'
4
+ require 'sunspot_rails'
3
5
 
4
6
  module Mailboxer
5
7
  class Engine < Rails::Engine