acts-as-messageable 0.4.7 → 0.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rspec +1 -1
- data/Gemfile +12 -12
- data/README.md +278 -265
- data/VERSION +1 -1
- data/acts-as-messageable.gemspec +2 -2
- data/lib/acts-as-messageable.rb +7 -7
- data/lib/acts-as-messageable/message.rb +97 -95
- data/lib/acts-as-messageable/model.rb +165 -157
- data/lib/acts-as-messageable/relation.rb +4 -0
- data/spec/acts-as-messageable_spec.rb +266 -234
- data/spec/custom-class_spec.rb +19 -4
- data/spec/spec_helper.rb +65 -61
- data/spec/support/admin.rb +3 -3
- data/spec/support/user.rb +7 -7
- metadata +3 -3
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
-fd -color
|
1
|
+
-fd -color
|
data/Gemfile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
gem "activerecord", ">= 3.0.0"
|
4
|
-
gem "activesupport", ">= 3.0.0"
|
5
|
-
gem "ancestry", "~> 1.3.0"
|
6
|
-
gem "railties", ">= 3.0.0"
|
7
|
-
|
8
|
-
group :development do
|
9
|
-
gem "rspec", "~> 2.11.0"
|
10
|
-
gem "jeweler", "~> 1.8.0"
|
11
|
-
gem "sqlite3"
|
12
|
-
end
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "activerecord", ">= 3.0.0"
|
4
|
+
gem "activesupport", ">= 3.0.0"
|
5
|
+
gem "ancestry", "~> 1.3.0"
|
6
|
+
gem "railties", ">= 3.0.0"
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.11.0"
|
10
|
+
gem "jeweler", "~> 1.8.0"
|
11
|
+
gem "sqlite3"
|
12
|
+
end
|
data/README.md
CHANGED
@@ -1,265 +1,278 @@
|
|
1
|
-
ActsAsMessageable
|
2
|
-
=================
|
3
|
-
|
4
|
-
The Acts As Messageable allows communication between the models.
|
5
|
-
|
6
|
-
[](http://travis-ci.org/LTe/acts-as-messageable) [](https://gemnasium.com/LTe/acts-as-messageable)
|
7
|
-
|
8
|
-
Usage
|
9
|
-
=====
|
10
|
-
|
11
|
-
To use it, add it to your Gemfile:
|
12
|
-
|
13
|
-
### Rails 3
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
gem 'acts-as-messageable'
|
17
|
-
```
|
18
|
-
|
19
|
-
### Rails 2
|
20
|
-
|
21
|
-
Use this [fork](http://github.com/openfirmware/acts-as-messageable)
|
22
|
-
Thanks for [@openfirmware](http://github.com/openfirmware)
|
23
|
-
|
24
|
-
```ruby
|
25
|
-
gem 'acts-as-messageable', :git => 'git://github.com/openfirmware/acts-as-messageable.git',
|
26
|
-
:branch => 'rails2.3.11_compatible'
|
27
|
-
```
|
28
|
-
|
29
|
-
Post instalation
|
30
|
-
================
|
31
|
-
|
32
|
-
```
|
33
|
-
rails g acts-as-messageable:migration table_name # default 'messages'
|
34
|
-
rake db:migrate
|
35
|
-
```
|
36
|
-
|
37
|
-
Usage
|
38
|
-
=====
|
39
|
-
|
40
|
-
```ruby
|
41
|
-
class User < ActiveRecord::Base
|
42
|
-
acts_as_messageable :table_name => "table_with_messages", # default 'messages'
|
43
|
-
:required => :body # default [:topic, :body]
|
44
|
-
:class_name => "CustomMessages" # default "ActsAsMessageable::Message",
|
45
|
-
:dependent => :destroy # default :nullify
|
46
|
-
end
|
47
|
-
```
|
48
|
-
|
49
|
-
Upgrade
|
50
|
-
=======
|
51
|
-
|
52
|
-
Just type once again
|
53
|
-
|
54
|
-
```
|
55
|
-
rails g acts-as-messageable:migration
|
56
|
-
```
|
57
|
-
|
58
|
-
And new migrations should be created.
|
59
|
-
|
60
|
-
```
|
61
|
-
~$ rails g acts-as-messageable:migration
|
62
|
-
create db/migrate/20110811223435_add_recipient_permanent_delete_and_sender_permanent_delete_to_messages.rb
|
63
|
-
```
|
64
|
-
|
65
|
-
Send message
|
66
|
-
============
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
@alice = User.first
|
70
|
-
@bob = User.last
|
71
|
-
|
72
|
-
@alice.send_message(@bob, "Message topic", "Hi bob!")
|
73
|
-
@bob.send_message(@alice, "Re: Message topic", "Hi alice!")
|
74
|
-
```
|
75
|
-
|
76
|
-
## With hash
|
77
|
-
|
78
|
-
```ruby
|
79
|
-
@alice.send_message(@bob, { :body => "Hash body", :topic => "Hash topic" })
|
80
|
-
```
|
81
|
-
|
82
|
-
Custom required (validation)
|
83
|
-
============================
|
84
|
-
|
85
|
-
In User model
|
86
|
-
|
87
|
-
```ruby
|
88
|
-
class User < ActiveRecord::Base
|
89
|
-
acts_as_messageable :required => :body
|
90
|
-
end
|
91
|
-
```
|
92
|
-
|
93
|
-
## With hash
|
94
|
-
|
95
|
-
```ruby
|
96
|
-
@alice.send_message(@bob, { :body => "Hash body" })
|
97
|
-
```
|
98
|
-
|
99
|
-
## Normal
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
@alice.send_message(@bob, "body")
|
103
|
-
```
|
104
|
-
|
105
|
-
## Required sequence
|
106
|
-
|
107
|
-
```ruby
|
108
|
-
class User < ActiveRecord::Base
|
109
|
-
acts_as_messageable :required => [:body, :topic]
|
110
|
-
end
|
111
|
-
|
112
|
-
@alice.send_message(@bob, "body", "topic")
|
113
|
-
```
|
114
|
-
|
115
|
-
## First topic
|
116
|
-
|
117
|
-
```ruby
|
118
|
-
class User < ActiveRecord::Base
|
119
|
-
acts_as_messageable :required => [:topic, :body]
|
120
|
-
end
|
121
|
-
|
122
|
-
@alice.send_message(@bob, "topic", "body")
|
123
|
-
```
|
124
|
-
|
125
|
-
Conversation
|
126
|
-
============
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
```
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
```ruby
|
142
|
-
@message = @alice.send_message(@bob, "Hello bob!", "How are you?")
|
143
|
-
@
|
144
|
-
```
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
```ruby
|
149
|
-
@message.
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
```
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
@
|
164
|
-
```
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
@alice.messages
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
```
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
@
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
@alice
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
```
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
```
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
1
|
+
ActsAsMessageable
|
2
|
+
=================
|
3
|
+
|
4
|
+
The Acts As Messageable allows communication between the models.
|
5
|
+
|
6
|
+
[](http://travis-ci.org/LTe/acts-as-messageable) [](https://gemnasium.com/LTe/acts-as-messageable)
|
7
|
+
|
8
|
+
Usage
|
9
|
+
=====
|
10
|
+
|
11
|
+
To use it, add it to your Gemfile:
|
12
|
+
|
13
|
+
### Rails 3
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'acts-as-messageable'
|
17
|
+
```
|
18
|
+
|
19
|
+
### Rails 2
|
20
|
+
|
21
|
+
Use this [fork](http://github.com/openfirmware/acts-as-messageable)
|
22
|
+
Thanks for [@openfirmware](http://github.com/openfirmware)
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem 'acts-as-messageable', :git => 'git://github.com/openfirmware/acts-as-messageable.git',
|
26
|
+
:branch => 'rails2.3.11_compatible'
|
27
|
+
```
|
28
|
+
|
29
|
+
Post instalation
|
30
|
+
================
|
31
|
+
|
32
|
+
```
|
33
|
+
rails g acts-as-messageable:migration table_name # default 'messages'
|
34
|
+
rake db:migrate
|
35
|
+
```
|
36
|
+
|
37
|
+
Usage
|
38
|
+
=====
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
class User < ActiveRecord::Base
|
42
|
+
acts_as_messageable :table_name => "table_with_messages", # default 'messages'
|
43
|
+
:required => :body # default [:topic, :body]
|
44
|
+
:class_name => "CustomMessages" # default "ActsAsMessageable::Message",
|
45
|
+
:dependent => :destroy # default :nullify
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
Upgrade
|
50
|
+
=======
|
51
|
+
|
52
|
+
Just type once again
|
53
|
+
|
54
|
+
```
|
55
|
+
rails g acts-as-messageable:migration
|
56
|
+
```
|
57
|
+
|
58
|
+
And new migrations should be created.
|
59
|
+
|
60
|
+
```
|
61
|
+
~$ rails g acts-as-messageable:migration
|
62
|
+
create db/migrate/20110811223435_add_recipient_permanent_delete_and_sender_permanent_delete_to_messages.rb
|
63
|
+
```
|
64
|
+
|
65
|
+
Send message
|
66
|
+
============
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
@alice = User.first
|
70
|
+
@bob = User.last
|
71
|
+
|
72
|
+
@alice.send_message(@bob, "Message topic", "Hi bob!")
|
73
|
+
@bob.send_message(@alice, "Re: Message topic", "Hi alice!")
|
74
|
+
```
|
75
|
+
|
76
|
+
## With hash
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
@alice.send_message(@bob, { :body => "Hash body", :topic => "Hash topic" })
|
80
|
+
```
|
81
|
+
|
82
|
+
Custom required (validation)
|
83
|
+
============================
|
84
|
+
|
85
|
+
In User model
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
class User < ActiveRecord::Base
|
89
|
+
acts_as_messageable :required => :body
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
## With hash
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
@alice.send_message(@bob, { :body => "Hash body" })
|
97
|
+
```
|
98
|
+
|
99
|
+
## Normal
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
@alice.send_message(@bob, "body")
|
103
|
+
```
|
104
|
+
|
105
|
+
## Required sequence
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
class User < ActiveRecord::Base
|
109
|
+
acts_as_messageable :required => [:body, :topic]
|
110
|
+
end
|
111
|
+
|
112
|
+
@alice.send_message(@bob, "body", "topic")
|
113
|
+
```
|
114
|
+
|
115
|
+
## First topic
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
class User < ActiveRecord::Base
|
119
|
+
acts_as_messageable :required => [:topic, :body]
|
120
|
+
end
|
121
|
+
|
122
|
+
@alice.send_message(@bob, "topic", "body")
|
123
|
+
```
|
124
|
+
|
125
|
+
Conversation
|
126
|
+
============
|
127
|
+
|
128
|
+
You can get conversation list from messages scope. For example:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
@message = @alice.send_message(@bob, "Hello bob!", "How are you?")
|
132
|
+
@reply_message = @bob.reply_to(@message, "Re: Hello bob!", "I'm fine!")
|
133
|
+
|
134
|
+
@alice.received_messages.conversations # => [@reply_message]
|
135
|
+
```
|
136
|
+
|
137
|
+
should receive list of latest messages in conversations (like in facebook).
|
138
|
+
|
139
|
+
To create conversation just reply to a message.
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
@message = @alice.send_message(@bob, "Hello bob!", "How are you?")
|
143
|
+
@message.reply("Re: Hello bob!", "I'm fine")
|
144
|
+
```
|
145
|
+
|
146
|
+
**Or with hash**
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
@message.reply(:topic => "Re: Hello bob!", :body => "I'm fine")
|
150
|
+
```
|
151
|
+
|
152
|
+
**Or in old style**
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
@message = @alice.send_message(@bob, "Hello bob!", "How are you?")
|
156
|
+
@reply_message = @bob.reply_to(@message, "Re: Hello bob!", "I'm fine!")
|
157
|
+
```
|
158
|
+
|
159
|
+
## Get conversation for a specific message
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
@message.conversation #=> [@message, @reply_message]
|
163
|
+
@reply_message.conversation #=> [@message, @reply_message]
|
164
|
+
```
|
165
|
+
|
166
|
+
Search
|
167
|
+
======
|
168
|
+
|
169
|
+
### Inbox
|
170
|
+
```ruby
|
171
|
+
@alice.received_messages
|
172
|
+
```
|
173
|
+
|
174
|
+
### Outbox
|
175
|
+
```ruby
|
176
|
+
@alice.sent_messages
|
177
|
+
```
|
178
|
+
### Inbox + Outbox. All messages connected with __@alice__
|
179
|
+
```ruby
|
180
|
+
@alice.messages
|
181
|
+
```
|
182
|
+
|
183
|
+
### Trash
|
184
|
+
```ruby
|
185
|
+
@alice.deleted_messages
|
186
|
+
```
|
187
|
+
|
188
|
+
## Filters
|
189
|
+
==========
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
@alice.messages.are_from(@bob) # all message form @bob
|
193
|
+
@alice.messages.are_to(@bob) # all message to @bob
|
194
|
+
@alice.messages.with_id(@id_of_message) # message with id id_of_message
|
195
|
+
@alice.messages.readed # all readed @alice messages
|
196
|
+
@alice.messages.unreaded # all unreaded @alice messages
|
197
|
+
```
|
198
|
+
|
199
|
+
|
200
|
+
**You can use multiple filters at the same time**
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
@alice.messages.are_from(@bob).are_to(@alice).readed # all message from @bob to @alice and readed
|
204
|
+
@alice.deleted_messages.are_from(@bob) # all deleted messages from @bob
|
205
|
+
```
|
206
|
+
|
207
|
+
Read messages
|
208
|
+
=============
|
209
|
+
|
210
|
+
### Read message
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
@message.open # open message
|
214
|
+
@message.read
|
215
|
+
@message.mark_as_read
|
216
|
+
```
|
217
|
+
|
218
|
+
### Unread message
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
@message.close # unread message
|
222
|
+
@message.mark_as_unread
|
223
|
+
```
|
224
|
+
|
225
|
+
|
226
|
+
Delete message
|
227
|
+
==============
|
228
|
+
|
229
|
+
**__We must know who delete message. That why we use *.process* method to save context__**
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
@message = @alice.send_message(@bob, "Topic", "Body")
|
233
|
+
|
234
|
+
@alice.messages.process do |message|
|
235
|
+
message.delete # @alice delete message
|
236
|
+
end
|
237
|
+
```
|
238
|
+
|
239
|
+
Now we can find message in **trash**
|
240
|
+
|
241
|
+
```ruby
|
242
|
+
@alice.deleted_messages #=> [@message]
|
243
|
+
```
|
244
|
+
|
245
|
+
We can delete the message **permanently**
|
246
|
+
|
247
|
+
```ruby
|
248
|
+
@alice.deleted_messages.process do |message|
|
249
|
+
message.delete
|
250
|
+
end
|
251
|
+
|
252
|
+
@alice.delete_message #=> []
|
253
|
+
```
|
254
|
+
|
255
|
+
Message has been deleted **permanently**
|
256
|
+
|
257
|
+
## Delete message without context
|
258
|
+
|
259
|
+
```ruby
|
260
|
+
@alice.delete_message(@message) # @alice delete @message
|
261
|
+
```
|
262
|
+
|
263
|
+
Restore message
|
264
|
+
===============
|
265
|
+
|
266
|
+
```ruby
|
267
|
+
@alice.deleted_messages.process do |m|
|
268
|
+
m.restore # @alice restore 'm' message from trash
|
269
|
+
end
|
270
|
+
```
|
271
|
+
|
272
|
+
## Restore message without context
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
@alice.restore_message(@message) # @alice restore message from trash
|
276
|
+
```
|
277
|
+
|
278
|
+
Copyright © 2011 Piotr Niełacny (http://ruby-blog.pl), released under the MIT license
|