acts-as-messageable 0.4.7 → 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
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
- [![Build Status](https://secure.travis-ci.org/LTe/acts-as-messageable.png)](http://travis-ci.org/LTe/acts-as-messageable) [![Dependency Status](https://gemnasium.com/LTe/acts-as-messageable.png)](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
- ```ruby
129
- @message = @alice.send_message(@bob, "Hello bob!", "How are you?")
130
- @message.reply("Re: Hello bob!", "I'm fine")
131
- ```
132
-
133
- **Or with hash**
134
-
135
- ```ruby
136
- @message.reply(:topic => "Re: Hello bob!", :body => "I'm fine")
137
- ```
138
-
139
- **Or in old style**
140
-
141
- ```ruby
142
- @message = @alice.send_message(@bob, "Hello bob!", "How are you?")
143
- @reply_message = @bob.reply_to(@message, "Re: Hello bob!", "I'm fine!")
144
- ```
145
-
146
- ## Get conversiation
147
-
148
- ```ruby
149
- @message.conversation #=> [@message, @reply_message]
150
- @reply_message.conversation #=> [@message, @reply_message]
151
- ```
152
-
153
- Search
154
- ======
155
-
156
- ### Inbox
157
- ```ruby
158
- @alice.received_messages
159
- ```
160
-
161
- ### Outbox
162
- ```ruby
163
- @alice.sent_messages
164
- ```
165
- ### Inbox + Outbox. All messages connected with __@alice__
166
- ```ruby
167
- @alice.messages
168
- ```
169
-
170
- ### Trash
171
- ```ruby
172
- @alice.deleted_messages
173
- ```
174
-
175
- ## Filters
176
- ==========
177
-
178
- ```ruby
179
- @alice.messages.are_from(@bob) # all message form @bob
180
- @alice.messages.are_to(@bob) # all message to @bob
181
- @alice.messages.with_id(@id_of_message) # message with id id_of_message
182
- @alice.messages.readed # all readed @alice messages
183
- @alice.messages.unread # all unreaded @alice messages
184
- ```
185
-
186
-
187
- **You can use multiple filters at the same time**
188
-
189
- ```ruby
190
- @alice.messages.are_from(@bob).are_to(@alice).readed # all message from @bob to @alice and readed
191
- @alice.deleted_messages.are_from(@bob) # all deleted messages from @bob
192
- ```
193
-
194
- Read messages
195
- =============
196
-
197
- ### Read message
198
-
199
- ```ruby
200
- @message.open # open message
201
- @message.read
202
- @message.mark_as_read
203
- ```
204
-
205
- ### Unread message
206
-
207
- ```ruby
208
- @message.close # unread message
209
- @message.mark_as_unread
210
- ```
211
-
212
-
213
- Delete message
214
- ==============
215
-
216
- **__We must know who delete message. That why we use *.process* method to save context__**
217
-
218
- ```ruby
219
- @message = @alice.send_message(@bob, "Topic", "Body")
220
-
221
- @alice.messages.process do |message|
222
- message.delete # @alice delete message
223
- end
224
- ```
225
-
226
- Now we can find message in **trash**
227
-
228
- ```ruby
229
- @alice.deleted_messages #=> [@message]
230
- ```
231
-
232
- We can delete the message **permanently**
233
-
234
- ```ruby
235
- @alice.deleted_messages.process do |message|
236
- message.delete
237
- end
238
-
239
- @alice.delete_message #=> []
240
- ```
241
-
242
- Message has been deleted **permanently**
243
-
244
- ## Delete message without context
245
-
246
- ```ruby
247
- @alice.delete_message(@message) # @alice delete @message
248
- ```
249
-
250
- Restore message
251
- ===============
252
-
253
- ```ruby
254
- @alice.deleted_messages.process do |m|
255
- m.restore # @alice restore 'm' message from trash
256
- end
257
- ```
258
-
259
- ## Restore message without context
260
-
261
- ```ruby
262
- @alice.restore_message(@message) # @alice restore message from trash
263
- ```
264
-
265
- Copyright © 2011 Piotr Niełacny (http://ruby-blog.pl), released under the MIT license
1
+ ActsAsMessageable
2
+ =================
3
+
4
+ The Acts As Messageable allows communication between the models.
5
+
6
+ [![Build Status](https://secure.travis-ci.org/LTe/acts-as-messageable.png)](http://travis-ci.org/LTe/acts-as-messageable) [![Dependency Status](https://gemnasium.com/LTe/acts-as-messageable.png)](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