private_mail 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,11 +22,11 @@ module PrivateMail
22
22
  migration_template "create_conversations.rb", "db/migrate/create_conversations.rb"
23
23
  migration_template "create_messages.rb", "db/migrate/create_messages.rb"
24
24
  migration_template "create_messages_recipients.rb", "db/migrate/create_messages_recipients.rb"
25
- migration_template "create_mail.rb", "db/migrate/create_mail.rb"
25
+ migration_template "create_mail_items.rb", "db/migrate/create_mail_items.rb"
26
26
  end
27
27
 
28
28
  def copy_models
29
- copy_file "../models/mail.rb", "app/models/mail.rb"
29
+ copy_file "../models/mail_item.rb", "app/models/mail_item.rb"
30
30
  copy_file "../models/message.rb", "app/models/message.rb"
31
31
  copy_file "../models/conversation.rb", "app/models/conversation.rb"
32
32
  end
@@ -1,7 +1,7 @@
1
1
  class Conversation < ActiveRecord::Base
2
2
  attr_reader :originator, :original_message, :last_sender, :last_message, :users
3
3
  has_many :messages
4
- has_many :mails
4
+ has_many :mail_items
5
5
  before_create :clean
6
6
  #looks like shit but isnt too bad
7
7
  #has_many :users, :through :messages, :source => :recipients, :uniq => true doesnt work due to recipients being a habtm association
@@ -1,5 +1,4 @@
1
- class Mail < ActiveRecord::Base
2
- self.table_name = "mail"
1
+ class MailItem < ActiveRecord::Base
3
2
  belongs_to :message
4
3
  belongs_to :user
5
4
  belongs_to :conversation
@@ -1,6 +1,6 @@
1
- class CreateMail < ActiveRecord::Migration
1
+ class CreateMailItems < ActiveRecord::Migration
2
2
  def self.up
3
- create_table :mail do |t|
3
+ create_table :mail_items do |t|
4
4
  t.column :user_id, :integer, :null => false
5
5
  t.column :message_id, :integer, :null => false
6
6
  t.column :conversation_id, :integer
@@ -13,6 +13,6 @@ class CreateMail < ActiveRecord::Migration
13
13
  end
14
14
 
15
15
  def self.down
16
- drop_table :mail
16
+ drop_table :mail_items
17
17
  end
18
18
  end
data/lib/mailbox.rb CHANGED
@@ -38,9 +38,9 @@ module PrivateMail
38
38
  # phil.mailbox[:inbox].mail_count(:unread)
39
39
  #
40
40
  def mail_count(filter = :all, options = {})
41
- default_options = {:conditions => ["mail.user_id = ?", @user.id]}
41
+ default_options = {:conditions => ["mail_items.user_id = ?", @user.id]}
42
42
  add_mailbox_condition!(default_options, @type)
43
- add_conditions!(default_options, "mail.read = ?", filter == :read) unless filter == :all
43
+ add_conditions!(default_options, "mail_items.read = ?", filter == :read) unless filter == :all
44
44
  return count_mail(default_options, options)
45
45
  end
46
46
 
@@ -49,7 +49,7 @@ module PrivateMail
49
49
  #====params:
50
50
  #options:: all valid find options are accepted as well as an additional conversation option.
51
51
  #* :conversation - Conversation object to filter mail only belonging to this conversation.
52
- #* :conditions - same as find conditions however the array version of conditions will not work, i.e., :conditions => ['mail.read = ?', false] will not work here.
52
+ #* :conditions - same as find conditions however the array version of conditions will not work, i.e., :conditions => ['mail_items.read = ?', false] will not work here.
53
53
  #* all other find options will work as expected.
54
54
  #
55
55
  #====returns:
@@ -65,7 +65,7 @@ module PrivateMail
65
65
  # phil.mailbox[:inbox].mail(:conversation => Conversation.find(23))
66
66
  #
67
67
  # #get all unread mail messages belonging to phil associated with conversation 23
68
- # phil.mailbox.mail(:conversation => Conversation.find(23), :conditions => 'mail.read = false')
68
+ # phil.mailbox.mail(:conversation => Conversation.find(23), :conditions => 'mail_items.read = false')
69
69
  #
70
70
  def mail(options = {})
71
71
  default_options = {}
@@ -88,7 +88,7 @@ module PrivateMail
88
88
  # phil.mailbox[:inbox].unread_mail
89
89
  #
90
90
  def unread_mail(options = {})
91
- default_options = {:conditions => ["mail.read = ?", false]}
91
+ default_options = {:conditions => ["mail_items.read = ?", false]}
92
92
  add_mailbox_condition!(default_options, @type)
93
93
  return get_mail(default_options, options)
94
94
  end
@@ -108,7 +108,7 @@ module PrivateMail
108
108
  # phil.mailbox[:inbox].read_mail
109
109
  #
110
110
  def read_mail(options = {})
111
- default_options = {:conditions => ["mail.read = ?", true]}
111
+ default_options = {:conditions => ["mail_items.read = ?", true]}
112
112
  add_mailbox_condition!(default_options, @type)
113
113
  return get_mail(default_options, options)
114
114
  end
@@ -148,8 +148,8 @@ module PrivateMail
148
148
  attributes = {:message => msg, :conversation => msg.conversation}
149
149
  attributes[:mailbox] = @type.to_s unless @type == :all
150
150
  attributes[:read] = msg.sender.id == @user.id
151
- mail_msg = Mail.new(attributes)
152
- @user.mail << mail_msg
151
+ mail_msg = MailItem.new(attributes)
152
+ @user.mail_items << mail_msg
153
153
  return mail_msg
154
154
  end
155
155
 
@@ -170,7 +170,7 @@ module PrivateMail
170
170
  def mark_as_read(options = {})
171
171
  default_options = {}
172
172
  add_mailbox_condition!(default_options, @type)
173
- return update_mail("mail.read = true", default_options, options)
173
+ return update_mail("mail_items.read = true", default_options, options)
174
174
  end
175
175
 
176
176
  #marks all the mail messages matched by the options and type as unread, except for sent messages.
@@ -188,9 +188,9 @@ module PrivateMail
188
188
  # phil.mailbox[:inbox].mark_as_unread()
189
189
  #
190
190
  def mark_as_unread(options = {})
191
- default_options = {:conditions => ["mail.mailbox != ?",@user.mailbox_types[:sent].to_s]}
191
+ default_options = {:conditions => ["mail_items.mailbox != ?",@user.mailbox_types[:sent].to_s]}
192
192
  add_mailbox_condition!(default_options, @type)
193
- return update_mail("mail.read = false", default_options, options)
193
+ return update_mail("mail_items.read = false", default_options, options)
194
194
  end
195
195
 
196
196
  #moves all mail matched by the options to the given mailbox. sent messages stay in the sentbox.
@@ -206,13 +206,13 @@ module PrivateMail
206
206
  add_mailbox_condition!(default_options, @type)
207
207
  if(!trash)
208
208
  #conditional update because sentmail is always sentmail - I believe case if the most widely supported conditional, mysql also has an if which would work as well but i think mysql is the only one to support it
209
- return update_mail("mail.trashed = false, mail.mailbox =
210
- CASE mail.mailbox
211
- WHEN '#{@user.mailbox_types[:sent].to_s}' THEN mail.mailbox
209
+ return update_mail("mail_items.trashed = false, mail_items.mailbox =
210
+ CASE mail_items.mailbox
211
+ WHEN '#{@user.mailbox_types[:sent].to_s}' THEN mail_items.mailbox
212
212
  ELSE '#{mailbox.to_s}'
213
213
  END", default_options, options)
214
214
  end
215
- return update_mail("mail.trashed = true", default_options, options)
215
+ return update_mail("mail_items.trashed = true", default_options, options)
216
216
  end
217
217
 
218
218
  #permanantly deletes all the mail messages matched by the options. Use move_to(:trash) instead if you want to send to user's trash without deleting.
@@ -221,7 +221,7 @@ module PrivateMail
221
221
  #options:: see mail for acceptable options.
222
222
  #
223
223
  def delete(options = {})
224
- default_options = {:conditions => ["mail.user_id = ?", @user.id]}
224
+ default_options = {:conditions => ["mail_items.user_id = ?", @user.id]}
225
225
  add_mailbox_condition!(default_options, @type)
226
226
  return delete_mail(default_options, options)
227
227
  end
@@ -237,7 +237,7 @@ module PrivateMail
237
237
  #options:: see mail for acceptable options.
238
238
  #
239
239
  def empty_trash(options = {})
240
- default_options = {:conditions => ["mail.user_id = ? AND mail.trashed = ?", @user.id, true]}
240
+ default_options = {:conditions => ["mail_items.user_id = ? AND mail_items.trashed = ?", @user.id, true]}
241
241
  add_mailbox_condition!(default_options, @type)
242
242
  return delete_mail(default_options, options)
243
243
  end
@@ -271,12 +271,12 @@ module PrivateMail
271
271
 
272
272
  def get_mail(default_options, options)
273
273
  build_options(default_options, options) unless options.empty?
274
- return @user.mail.find(:all, default_options)
274
+ return @user.mail_items.find(:all, default_options)
275
275
  end
276
276
 
277
277
  def update_mail(updates, default_options, options)
278
278
  build_options(default_options, options) unless options.empty?
279
- return @user.mail.update_all(updates, default_options[:conditions])
279
+ return @user.mail_items.update_all(updates, default_options[:conditions])
280
280
  end
281
281
 
282
282
  def delete_mail(default_options, options)
@@ -300,7 +300,7 @@ module PrivateMail
300
300
  def only_latest(mail)
301
301
  convos = []
302
302
  latest = []
303
- mail.each do |m|
303
+ mail_items.each do |m|
304
304
  next if(convos.include?(m.conversation_id))
305
305
  convos << m.conversation_id
306
306
  latest << m
@@ -310,8 +310,8 @@ module PrivateMail
310
310
 
311
311
  def add_mailbox_condition!(options, mailbox_type)
312
312
  return if mailbox_type == :all
313
- return add_conditions!(options, "mail.mailbox = ? AND mail.trashed = ?", mailbox_type.to_s, false) unless mailbox_type == @user.mailbox_types[:deleted]
314
- return add_conditions!(options, "mail.trashed = ?", true)
313
+ return add_conditions!(options, "mail_items.mailbox = ? AND mail_items.trashed = ?", mailbox_type.to_s, false) unless mailbox_type == @user.mailbox_types[:deleted]
314
+ return add_conditions!(options, "mail_items.trashed = ?", true)
315
315
  end
316
316
 
317
317
  def add_conversation_condition!(options, conversation)
data/lib/private_mail.rb CHANGED
@@ -27,7 +27,7 @@ module PrivateMail
27
27
  # acts_as_messageable :received => :in, :sent => :sent, :deleted => :garbage
28
28
  def acts_as_messageable(options = {})
29
29
  cattr_accessor :mailbox_types
30
- has_many :mail, :order => 'created_at DESC', :dependent => :delete_all
30
+ has_many :mail_items, :order => 'created_at DESC', :dependent => :delete_all
31
31
 
32
32
  self.mailbox_types = {
33
33
  :received => :inbox,
@@ -1,3 +1,3 @@
1
1
  module PrivateMail
2
- VERSION = "0.0.1" unless defined? PrivateMail::VERSION
2
+ VERSION = "0.0.2" unless defined? PrivateMail::VERSION
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: private_mail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-31 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2170459640 !ruby/object:Gem::Requirement
16
+ requirement: &2169805040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2170459640
24
+ version_requirements: *2169805040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2170459220 !ruby/object:Gem::Requirement
27
+ requirement: &2169804620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,8 +32,9 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2170459220
36
- description: ''
35
+ version_requirements: *2169804620
36
+ description: Enables User models in Rails 3.1+ apps to have simple private messaging
37
+ capabilites between them.
37
38
  email: john@mcdowall.info
38
39
  executables: []
39
40
  extensions: []
@@ -41,10 +42,10 @@ extra_rdoc_files: []
41
42
  files:
42
43
  - lib/generators/private_mail/install/install_generator.rb
43
44
  - lib/generators/private_mail/install/models/conversation.rb
44
- - lib/generators/private_mail/install/models/mail.rb
45
+ - lib/generators/private_mail/install/models/mail_item.rb
45
46
  - lib/generators/private_mail/install/models/message.rb
46
47
  - lib/generators/private_mail/install/templates/create_conversations.rb
47
- - lib/generators/private_mail/install/templates/create_mail.rb
48
+ - lib/generators/private_mail/install/templates/create_mail_items.rb
48
49
  - lib/generators/private_mail/install/templates/create_messages.rb
49
50
  - lib/generators/private_mail/install/templates/create_messages_recipients.rb
50
51
  - lib/mailbox.rb
@@ -64,7 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
65
  version: '0'
65
66
  segments:
66
67
  - 0
67
- hash: -1834868077319262402
68
+ hash: -3700018115756833954
68
69
  required_rubygems_version: !ruby/object:Gem::Requirement
69
70
  none: false
70
71
  requirements:
@@ -76,5 +77,6 @@ rubyforge_project:
76
77
  rubygems_version: 1.8.11
77
78
  signing_key:
78
79
  specification_version: 3
79
- summary: ''
80
+ summary: This gem provides basic simple private messaging, based on the bondes of
81
+ acts_as_messageable.
80
82
  test_files: []