acts-as-messageable 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/README.md +165 -0
- data/VERSION +1 -1
- data/acts-as-messageable.gemspec +11 -14
- data/lib/generators/acts-as-messageable/migration/migration_generator.rb +3 -4
- data/spec/acts-as-messageable_spec.rb +108 -88
- metadata +69 -128
- data/README.rdoc +0 -118
data/Gemfile
CHANGED
data/README.md
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
|
2
|
+
ActsAsMessageable
|
3
|
+
=================
|
4
|
+
|
5
|
+
The Acts As Messageable allows communication between the models.
|
6
|
+
|
7
|
+
[![Build Status](http://travis-ci.org/LTe/acts-as-messageable.png)](http://github.com/LTe/acts-as-messageable)
|
8
|
+
|
9
|
+
Usage
|
10
|
+
=====
|
11
|
+
|
12
|
+
To use it, add it to your Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'acts-as-messageable'
|
16
|
+
```
|
17
|
+
|
18
|
+
Post instalation
|
19
|
+
================
|
20
|
+
|
21
|
+
```
|
22
|
+
rails g acts-as-messageable:migration table_name # default 'messages'
|
23
|
+
rake db:migrate
|
24
|
+
```
|
25
|
+
|
26
|
+
Usage
|
27
|
+
=====
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class User < ActiveRecord::Base
|
31
|
+
acts_as_messageable :table_name => "table_with_messages", # default 'messages'
|
32
|
+
:required => :body # default [:topic, :body]
|
33
|
+
:class_name => "CustomMessages" # default "ActsAsMessageable::Message"
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
Upgrade
|
38
|
+
=======
|
39
|
+
|
40
|
+
Just type once again
|
41
|
+
|
42
|
+
```
|
43
|
+
rails g acts-as-messageable:migration
|
44
|
+
```
|
45
|
+
|
46
|
+
And new migrations should be created.
|
47
|
+
|
48
|
+
```
|
49
|
+
~$ rails g acts-as-messageable:migration
|
50
|
+
create db/migrate/20110811223435_add_recipient_permanent_delete_and_sender_permanent_delete_to_messages.rb
|
51
|
+
```
|
52
|
+
|
53
|
+
Send message
|
54
|
+
============
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
@alice = User.first
|
58
|
+
@bob = User.last
|
59
|
+
|
60
|
+
@alice.send_message(@bob, "Message topic", "Hi bob!")
|
61
|
+
@bob.send_message(@alice, "Re: Message topic", "Hi alice!")
|
62
|
+
```
|
63
|
+
|
64
|
+
With hash
|
65
|
+
=========
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
@alice.send_message(@bob, { :body => "Hash body", :topic => "Hash topic" })
|
69
|
+
```
|
70
|
+
|
71
|
+
Custom required
|
72
|
+
===============
|
73
|
+
|
74
|
+
In User model
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
class User < ActiveRecord::Base
|
78
|
+
acts_as_messageable :required => :body
|
79
|
+
end
|
80
|
+
|
81
|
+
@alice.send_message(@bob, { :body => "Hash body" })
|
82
|
+
```
|
83
|
+
|
84
|
+
or
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
@alice.send_message(@bob, "body")
|
88
|
+
```
|
89
|
+
|
90
|
+
Required sequence
|
91
|
+
=================
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
class User < ActiveRecord::Base
|
95
|
+
acts_as_messageable :required => [:body, :topic]
|
96
|
+
end
|
97
|
+
|
98
|
+
@alice.send_message(@bob, "body", "topic")
|
99
|
+
```
|
100
|
+
|
101
|
+
Conversation
|
102
|
+
============
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
@message = @alice.send_message(@bob, "Hello bob!", "How are you?")
|
106
|
+
@reply_message = @bob.reply_to(@message, "Re: Hello bob!", "I'm fine!")
|
107
|
+
# or @bob.reply_to(@message, :topic => "Re: Hello bob!", :body => "I'm fine!")
|
108
|
+
|
109
|
+
@message.conversation #=> [@message, @reply_message]
|
110
|
+
@reply_message.conversation #=> [@message, @reply_message]
|
111
|
+
```
|
112
|
+
|
113
|
+
Search
|
114
|
+
===
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
@alice.messages # all messages connected with @alice (inbox/outbox)
|
118
|
+
@alice.received_messages # @alice inbox
|
119
|
+
@alice.sent_messages # @alice outbox
|
120
|
+
|
121
|
+
@alice.deleted_messages # all messages connected with @alice (trash)
|
122
|
+
|
123
|
+
@alice.messages.are_from(@bob) # all message form @bob
|
124
|
+
@alice.messages.are_to(@bob) # all message to @bob
|
125
|
+
@alice.messages.with_id(@id_of_message) # message with id id_of_message
|
126
|
+
@alice.messages.readed # all readed @alice messages
|
127
|
+
@alice.messages.unread # all unreaded @alice messages
|
128
|
+
|
129
|
+
@alice.received_messages.are_from(@bob) # all messages from bob (inbox)
|
130
|
+
@alice.sent_messages.are_to(@bob) # all messages do bob (outbox)
|
131
|
+
```
|
132
|
+
|
133
|
+
You can use multiple filters at the same time
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
@alice.messages.are_from(@bob).are_to(@alice).readed # all message from @bob to @alice and readed
|
137
|
+
@alice.deleted_messages.are_from(@bob) # all deleted messages from @bob
|
138
|
+
```
|
139
|
+
|
140
|
+
Delete message
|
141
|
+
==============
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
@message = @alice.send_message(@bob, "Topic", "Body")
|
145
|
+
|
146
|
+
@alice.messages.process do |message|
|
147
|
+
message.delete
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
151
|
+
Now we can find message in trash
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
@alice.deleted_messages #=> [@message]
|
155
|
+
|
156
|
+
@alice.deleted_messages.process do |message|
|
157
|
+
message.delete
|
158
|
+
end
|
159
|
+
|
160
|
+
@alice.delete_message #=> []
|
161
|
+
```
|
162
|
+
|
163
|
+
Message was permanent delete
|
164
|
+
|
165
|
+
Copyright © 2011 Piotr Niełacny (http://ruby-blog.pl), released under the MIT license
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/acts-as-messageable.gemspec
CHANGED
@@ -4,22 +4,22 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.4.
|
7
|
+
s.name = "acts-as-messageable"
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date =
|
13
|
-
s.email =
|
11
|
+
s.authors = ["Piotr Nielacny"]
|
12
|
+
s.date = "2011-11-16"
|
13
|
+
s.email = "piotr.nielacny@gmail.com"
|
14
14
|
s.extra_rdoc_files = [
|
15
|
-
"README.
|
15
|
+
"README.md"
|
16
16
|
]
|
17
17
|
s.files = [
|
18
18
|
".rspec",
|
19
19
|
".travis.yml",
|
20
20
|
"Gemfile",
|
21
21
|
"MIT-LICENSE",
|
22
|
-
"README.
|
22
|
+
"README.md",
|
23
23
|
"Rakefile",
|
24
24
|
"VERSION",
|
25
25
|
"acts-as-messageable.gemspec",
|
@@ -37,10 +37,10 @@ Gem::Specification.new do |s|
|
|
37
37
|
"spec/spec_helper.rb",
|
38
38
|
"spec/support/user.rb"
|
39
39
|
]
|
40
|
-
s.homepage =
|
41
|
-
s.require_paths = [
|
42
|
-
s.rubygems_version =
|
43
|
-
s.summary =
|
40
|
+
s.homepage = "http://github.com/LTe/acts-as-messageable"
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = "1.8.10"
|
43
|
+
s.summary = "Make user messageable!;-)"
|
44
44
|
|
45
45
|
if s.respond_to? :specification_version then
|
46
46
|
s.specification_version = 3
|
@@ -50,7 +50,6 @@ Gem::Specification.new do |s|
|
|
50
50
|
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
|
51
51
|
s.add_runtime_dependency(%q<ancestry>, ["~> 1.2.4"])
|
52
52
|
s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
|
53
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
53
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
55
54
|
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
56
55
|
else
|
@@ -58,7 +57,6 @@ Gem::Specification.new do |s|
|
|
58
57
|
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
59
58
|
s.add_dependency(%q<ancestry>, ["~> 1.2.4"])
|
60
59
|
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
61
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
60
|
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
63
61
|
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
64
62
|
end
|
@@ -67,7 +65,6 @@ Gem::Specification.new do |s|
|
|
67
65
|
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
68
66
|
s.add_dependency(%q<ancestry>, ["~> 1.2.4"])
|
69
67
|
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
70
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
71
68
|
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
72
69
|
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
73
70
|
end
|
@@ -11,13 +11,12 @@ module ActsAsMessageable
|
|
11
11
|
argument :table_name, :type => :string, :default => "messages"
|
12
12
|
|
13
13
|
def self.next_migration_number(dirname)
|
14
|
-
|
14
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
15
15
|
end
|
16
16
|
|
17
17
|
def create_migration_file
|
18
|
-
migration_template '
|
19
|
-
migration_template '
|
18
|
+
migration_template 'migration.rb', 'db/migrate/create_messages_table.rb' rescue nil
|
19
|
+
migration_template 'migration_permanent.rb', 'db/migrate/add_recipient_permanent_delete_and_sender_permanent_delete_to_messages.rb' rescue nil
|
20
20
|
end
|
21
|
-
|
22
21
|
end
|
23
22
|
end
|
@@ -4,140 +4,160 @@ class User < ActiveRecord::Base
|
|
4
4
|
acts_as_messageable
|
5
5
|
end
|
6
6
|
|
7
|
+
def send_message(from=@bob, to=@alice, topic="Topic", body="Body")
|
8
|
+
from.send_message(to, topic, body)
|
9
|
+
end
|
10
|
+
|
7
11
|
describe "ActsAsMessageable" do
|
8
12
|
|
9
13
|
before(:all) do
|
10
14
|
User.acts_as_messageable
|
11
15
|
end
|
12
16
|
|
13
|
-
|
14
|
-
|
17
|
+
describe "prepare for specs" do
|
18
|
+
it "should be two users in database" do
|
19
|
+
User.count.should == 2
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
describe "send messages" do
|
24
|
+
it "alice should have one message" do
|
25
|
+
send_message
|
26
|
+
@alice.messages.count.should == 1
|
27
|
+
end
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
it "alice should have one message from bob" do
|
30
|
+
send_message
|
31
|
+
@alice.messages.are_from(@bob).count.should == 1
|
32
|
+
end
|
33
|
+
|
34
|
+
it "bob should have one message" do
|
35
|
+
send_message
|
36
|
+
@bob.messages.count.should == 1
|
37
|
+
end
|
28
38
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
m.open
|
39
|
+
it "bob should have one message to alice in outbox" do
|
40
|
+
send_message
|
41
|
+
@bob.sent_messages.are_to(@alice).count.should == 1
|
33
42
|
end
|
34
43
|
|
35
|
-
|
44
|
+
it "bob should have one open message from alice" do
|
45
|
+
send_message
|
46
|
+
@alice.messages.are_from(@bob).process { |m| m.open }
|
47
|
+
@alice.messages.readed.count.should == 1
|
48
|
+
end
|
36
49
|
end
|
37
50
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
m
|
51
|
+
describe "delete messages" do
|
52
|
+
it "bob should have one deleted message from alice" do
|
53
|
+
send_message
|
54
|
+
@bob.messages.process do |m|
|
55
|
+
m.delete
|
56
|
+
end
|
57
|
+
|
58
|
+
@bob.messages.each do |m|
|
59
|
+
m.recipient_delete.should == true
|
60
|
+
m.sender_delete.should == false
|
61
|
+
end
|
62
|
+
|
63
|
+
@bob.deleted_messages.count.should == 1
|
64
|
+
@bob.messages.count.should == 0
|
42
65
|
end
|
43
66
|
|
44
|
-
|
45
|
-
|
46
|
-
|
67
|
+
it "received_messages and sent_messages should work with .process method" do
|
68
|
+
@message = send_message
|
69
|
+
|
70
|
+
@bob.sent_messages.count.should == 1
|
71
|
+
@alice.received_messages.count.should == 1
|
72
|
+
|
73
|
+
@bob.sent_messages.process { |m| m.delete }
|
74
|
+
@bob.sent_messages.count.should == 0
|
75
|
+
@alice.received_messages.count.should == 1
|
76
|
+
|
77
|
+
@alice.received_messages.process { |m| m.delete }
|
78
|
+
@alice.received_messages.count.should == 0
|
47
79
|
end
|
48
80
|
|
49
|
-
|
50
|
-
|
81
|
+
it "message should permanent delete" do
|
82
|
+
@message = send_message
|
83
|
+
@alice.messages.process { |m| m.delete }
|
84
|
+
@alice.messages.count.should == 0
|
85
|
+
|
86
|
+
@alice.deleted_messages.count.should == 1
|
87
|
+
@alice.deleted_messages.process { |m| m.delete }
|
88
|
+
@alice.deleted_messages.count.should == 0
|
89
|
+
|
90
|
+
@message.reload
|
91
|
+
@message.recipient_permanent_delete.should == true
|
92
|
+
|
93
|
+
@bob.sent_messages.count.should == 1
|
94
|
+
end
|
51
95
|
end
|
52
96
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
97
|
+
describe "read/unread feature" do
|
98
|
+
it "alice should have one unread message from bob" do
|
99
|
+
send_message
|
100
|
+
@alice.messages.are_from(@bob).unread.count.should == 1
|
101
|
+
@alice.messages.are_from(@bob).readed.count.should == 0
|
102
|
+
end
|
57
103
|
end
|
58
104
|
|
59
105
|
it "should be in database message with id ..." do
|
60
|
-
message_id =
|
106
|
+
message_id = send_message.id
|
61
107
|
@bob.messages.with_id(message_id).count.should == 1
|
62
108
|
end
|
63
109
|
|
64
110
|
it "message should have proper topic" do
|
65
|
-
|
111
|
+
send_message
|
66
112
|
@bob.messages.count.should == 1
|
67
113
|
@bob.messages.first.topic == "Topic"
|
68
|
-
@bob.messages.first.body == "Message body"
|
69
114
|
end
|
70
115
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
@reply_message.conversation.size.should == 2
|
76
|
-
@reply_message.conversation.first.topic.should == "Topic"
|
77
|
-
@reply_message.conversation.last.topic.should == "Re: Topic"
|
78
|
-
end
|
116
|
+
describe "conversation" do
|
117
|
+
it "bob send message to alice, and alice reply to bob message and show proper tree" do
|
118
|
+
@message = send_message
|
119
|
+
@reply_message = @alice.reply_to(@message, "Re: Topic", "Body")
|
79
120
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
@reply_reply_message = @bob.reply_to(@reply_message, "Re: Re: Topic", "Body")
|
84
|
-
|
85
|
-
[@message, @reply_message, @reply_reply_message].each do |m|
|
86
|
-
m.conversation.size.should == 3
|
121
|
+
@reply_message.conversation.size.should == 2
|
122
|
+
@reply_message.conversation.first.topic.should == "Topic"
|
123
|
+
@reply_message.conversation.last.topic.should == "Re: Topic"
|
87
124
|
end
|
88
125
|
|
89
|
-
|
90
|
-
|
91
|
-
|
126
|
+
it "bob send message to alice, alice answer, and bob answer for alice answer" do
|
127
|
+
@message = send_message
|
128
|
+
@reply_message = @alice.reply_to(@message, "Re: Topic", "Body")
|
129
|
+
@reply_reply_message = @bob.reply_to(@reply_message, "Re: Re: Topic", "Body")
|
92
130
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
@message.body.should == "Body"
|
97
|
-
end
|
131
|
+
[@message, @reply_message, @reply_reply_message].each do |m|
|
132
|
+
m.conversation.size.should == 3
|
133
|
+
end
|
98
134
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
@alice.messages.first.body.should == "First message"
|
135
|
+
@message.conversation.last.should == @reply_reply_message
|
136
|
+
@reply_reply_message.conversation.last.should == @reply_reply_message
|
137
|
+
end
|
103
138
|
end
|
104
139
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
@alice.deleted_messages.count.should == 0
|
113
|
-
|
114
|
-
@message.reload
|
115
|
-
@message.recipient_permanent_delete.should == true
|
140
|
+
describe "send messages with hash" do
|
141
|
+
it "send message with hash" do
|
142
|
+
@message = @bob.send_message(@alice, {:body => "Body", :topic => "Topic"})
|
143
|
+
@message.topic.should == "Topic"
|
144
|
+
@message.body.should == "Body"
|
145
|
+
end
|
146
|
+
end
|
116
147
|
|
117
|
-
|
148
|
+
it "messages should return in right order :created_at" do
|
149
|
+
@message = send_message
|
150
|
+
@message = send_message(@bob, @alice, "Example", "Example Body")
|
151
|
+
@alice.messages.first.body.should == "Body"
|
118
152
|
end
|
119
153
|
|
120
154
|
it "received_messages should return ActiveRecord::Relation" do
|
121
|
-
|
155
|
+
send_message
|
122
156
|
@alice.received_messages.class.should == ActiveRecord::Relation
|
123
157
|
end
|
124
158
|
|
125
159
|
it "sent_messages should return ActiveRecord::Relation" do
|
126
|
-
|
160
|
+
send_message
|
127
161
|
@bob.sent_messages.class.should == ActiveRecord::Relation
|
128
162
|
end
|
129
|
-
|
130
|
-
it "received_messages and sent_messages should work with .process method" do
|
131
|
-
@message = @bob.send_message(@alice, "Helou", "Alice")
|
132
|
-
|
133
|
-
@bob.sent_messages.count.should == 1
|
134
|
-
@alice.received_messages.count.should == 1
|
135
|
-
|
136
|
-
@bob.sent_messages.process { |m| m.delete }
|
137
|
-
@bob.sent_messages.count.should == 0
|
138
|
-
@alice.received_messages.count.should == 1
|
139
|
-
|
140
|
-
@alice.received_messages.process { |m| m.delete }
|
141
|
-
@alice.received_messages.count.should == 0
|
142
|
-
end
|
143
163
|
end
|
metadata
CHANGED
@@ -1,146 +1,94 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts-as-messageable
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
- 0
|
10
|
-
version: 0.4.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Piotr Nielacny
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2011-11-16 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
16
|
+
requirement: &69822268751920 !ruby/object:Gem::Requirement
|
23
17
|
none: false
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
hash: 7
|
28
|
-
segments:
|
29
|
-
- 3
|
30
|
-
- 0
|
31
|
-
- 0
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
32
21
|
version: 3.0.0
|
33
|
-
version_requirements: *id001
|
34
|
-
name: activerecord
|
35
|
-
prerelease: false
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
22
|
type: :runtime
|
38
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *69822268751920
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
requirement: &69822268749940 !ruby/object:Gem::Requirement
|
39
28
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 7
|
44
|
-
segments:
|
45
|
-
- 3
|
46
|
-
- 0
|
47
|
-
- 0
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
48
32
|
version: 3.0.0
|
49
|
-
version_requirements: *id002
|
50
|
-
name: activesupport
|
51
|
-
prerelease: false
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
33
|
type: :runtime
|
54
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *69822268749940
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: ancestry
|
38
|
+
requirement: &69822268747920 !ruby/object:Gem::Requirement
|
55
39
|
none: false
|
56
|
-
requirements:
|
40
|
+
requirements:
|
57
41
|
- - ~>
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
hash: 23
|
60
|
-
segments:
|
61
|
-
- 1
|
62
|
-
- 2
|
63
|
-
- 4
|
42
|
+
- !ruby/object:Gem::Version
|
64
43
|
version: 1.2.4
|
65
|
-
|
66
|
-
name: ancestry
|
44
|
+
type: :runtime
|
67
45
|
prerelease: false
|
68
|
-
|
69
|
-
|
70
|
-
|
46
|
+
version_requirements: *69822268747920
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &69822268746840 !ruby/object:Gem::Requirement
|
71
50
|
none: false
|
72
|
-
requirements:
|
51
|
+
requirements:
|
73
52
|
- - ~>
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
hash: 23
|
76
|
-
segments:
|
77
|
-
- 2
|
78
|
-
- 6
|
79
|
-
- 0
|
53
|
+
- !ruby/object:Gem::Version
|
80
54
|
version: 2.6.0
|
81
|
-
version_requirements: *id004
|
82
|
-
name: rspec
|
83
|
-
prerelease: false
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
55
|
type: :development
|
86
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
|
-
requirements:
|
89
|
-
- - ~>
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
hash: 23
|
92
|
-
segments:
|
93
|
-
- 1
|
94
|
-
- 0
|
95
|
-
- 0
|
96
|
-
version: 1.0.0
|
97
|
-
version_requirements: *id005
|
98
|
-
name: bundler
|
99
56
|
prerelease: false
|
100
|
-
|
101
|
-
|
102
|
-
|
57
|
+
version_requirements: *69822268746840
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &69822268745520 !ruby/object:Gem::Requirement
|
103
61
|
none: false
|
104
|
-
requirements:
|
62
|
+
requirements:
|
105
63
|
- - ~>
|
106
|
-
- !ruby/object:Gem::Version
|
107
|
-
hash: 15
|
108
|
-
segments:
|
109
|
-
- 1
|
110
|
-
- 6
|
111
|
-
- 0
|
64
|
+
- !ruby/object:Gem::Version
|
112
65
|
version: 1.6.0
|
113
|
-
version_requirements: *id006
|
114
|
-
name: jeweler
|
115
|
-
prerelease: false
|
116
|
-
- !ruby/object:Gem::Dependency
|
117
66
|
type: :development
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
- - ">="
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
hash: 3
|
124
|
-
segments:
|
125
|
-
- 0
|
126
|
-
version: "0"
|
127
|
-
version_requirements: *id007
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *69822268745520
|
69
|
+
- !ruby/object:Gem::Dependency
|
128
70
|
name: sqlite3-ruby
|
71
|
+
requirement: &69822268743820 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
129
78
|
prerelease: false
|
79
|
+
version_requirements: *69822268743820
|
130
80
|
description:
|
131
81
|
email: piotr.nielacny@gmail.com
|
132
82
|
executables: []
|
133
|
-
|
134
83
|
extensions: []
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
files:
|
84
|
+
extra_rdoc_files:
|
85
|
+
- README.md
|
86
|
+
files:
|
139
87
|
- .rspec
|
140
88
|
- .travis.yml
|
141
89
|
- Gemfile
|
142
90
|
- MIT-LICENSE
|
143
|
-
- README.
|
91
|
+
- README.md
|
144
92
|
- Rakefile
|
145
93
|
- VERSION
|
146
94
|
- acts-as-messageable.gemspec
|
@@ -159,36 +107,29 @@ files:
|
|
159
107
|
- spec/support/user.rb
|
160
108
|
homepage: http://github.com/LTe/acts-as-messageable
|
161
109
|
licenses: []
|
162
|
-
|
163
110
|
post_install_message:
|
164
111
|
rdoc_options: []
|
165
|
-
|
166
|
-
require_paths:
|
112
|
+
require_paths:
|
167
113
|
- lib
|
168
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
115
|
none: false
|
170
|
-
requirements:
|
171
|
-
- -
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
|
174
|
-
segments:
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
segments:
|
175
121
|
- 0
|
176
|
-
|
177
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
hash: -3869198984656405401
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
124
|
none: false
|
179
|
-
requirements:
|
180
|
-
- -
|
181
|
-
- !ruby/object:Gem::Version
|
182
|
-
|
183
|
-
segments:
|
184
|
-
- 0
|
185
|
-
version: "0"
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
186
129
|
requirements: []
|
187
|
-
|
188
130
|
rubyforge_project:
|
189
|
-
rubygems_version: 1.8.
|
131
|
+
rubygems_version: 1.8.10
|
190
132
|
signing_key:
|
191
133
|
specification_version: 3
|
192
134
|
summary: Make user messageable!;-)
|
193
135
|
test_files: []
|
194
|
-
|
data/README.rdoc
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
|
2
|
-
= ActsAsMessageable
|
3
|
-
The Acts As Messageable allows communication between the models.
|
4
|
-
|
5
|
-
http://travis-ci.org/LTe/acts-as-messageable.png
|
6
|
-
|
7
|
-
|
8
|
-
== Usage
|
9
|
-
To use it, add it to your Gemfile:
|
10
|
-
|
11
|
-
gem 'acts-as-messageable'
|
12
|
-
|
13
|
-
== Post instalation
|
14
|
-
|
15
|
-
rails g acts-as-messageable:migration table_name # default 'messages'
|
16
|
-
rake db:migrate
|
17
|
-
|
18
|
-
== Usage
|
19
|
-
|
20
|
-
class User < ActiveRecord::Base
|
21
|
-
acts_as_messageable :table_name => "table_with_messages", # default 'messages'
|
22
|
-
:required => :body # default [:topic, :body]
|
23
|
-
:class_name => "CustomMessages" # default "ActsAsMessageable::Message"
|
24
|
-
end
|
25
|
-
|
26
|
-
== Upgrade
|
27
|
-
Just type once again
|
28
|
-
|
29
|
-
rails g acts-as-messageable:migration
|
30
|
-
|
31
|
-
And new migrations should be created.
|
32
|
-
|
33
|
-
~$ rails g acts-as-messageable:migration
|
34
|
-
create db/migrate/20110811223435_add_recipient_permanent_delete_and_sender_permanent_delete_to_messages.rb
|
35
|
-
Another migration is already named create_messages_table: /home/lite/work/acts_test/db/migrate/20110811184810_create_messages_table.rb
|
36
|
-
|
37
|
-
== Send message
|
38
|
-
|
39
|
-
@alice = User.first
|
40
|
-
@bob = User.last
|
41
|
-
|
42
|
-
@alice.send_message(@bob, "Message topic", "Hi bob!")
|
43
|
-
@bob.send_message(@alice, "Re: Message topic", "Hi alice!")
|
44
|
-
|
45
|
-
=== With hash
|
46
|
-
|
47
|
-
@alice.send_message(@bob, { :body => "Hash body", :topic => "Hash topic" })
|
48
|
-
|
49
|
-
=== Custom required
|
50
|
-
|
51
|
-
In User model
|
52
|
-
class User < ActiveRecord::Base
|
53
|
-
acts_as_messageable :required => :body
|
54
|
-
end
|
55
|
-
|
56
|
-
@alice.send_message(@bob, { :body => "Hash body" })
|
57
|
-
or
|
58
|
-
@alice.send_message(@bob, "body")
|
59
|
-
|
60
|
-
==== Required sequence
|
61
|
-
|
62
|
-
|
63
|
-
class User < ActiveRecord::Base
|
64
|
-
acts_as_messageable :required => [:body, :topic]
|
65
|
-
end
|
66
|
-
|
67
|
-
@alice.send_message(@bob, "body", "topic")
|
68
|
-
|
69
|
-
== Conversation
|
70
|
-
@message = @alice.send_message(@bob, "Hello bob!", "How are you?")
|
71
|
-
@reply_message = @bob.reply_to(@message, "Re: Hello bob!", "I'm fine!")
|
72
|
-
# or @bob.reply_to(@message, :topic => "Re: Hello bob!", :body => "I'm fine!")
|
73
|
-
|
74
|
-
@message.conversation #=> [@message, @reply_message]
|
75
|
-
@reply_message.conversation #=> [@message, @reply_message]
|
76
|
-
|
77
|
-
== API
|
78
|
-
@alice.messages # all messages connected with @alice (inbox/outbox)
|
79
|
-
@alice.received_messages # @alice inbox
|
80
|
-
@alice.sent_messages # @alice outbox
|
81
|
-
|
82
|
-
@alice.deleted_messages # all messages connected with @alice (trash)
|
83
|
-
|
84
|
-
@alice.messages.are_from(@bob) # all message form @bob
|
85
|
-
@alice.messages.are_to(@bob) # all message to @bob
|
86
|
-
@alice.messages.with_id(@id_of_message) # message with id id_of_message
|
87
|
-
@alice.messages.readed # all readed @alice messages
|
88
|
-
@alice.messages.unread # all unreaded @alice messages
|
89
|
-
|
90
|
-
@alice.received_messages.are_from(@bob) # all messages from bob (inbox)
|
91
|
-
@alice.sent_messages.are_to(@bob) # all messages do bob (outbox)
|
92
|
-
|
93
|
-
You can use multiple filters at the same time
|
94
|
-
|
95
|
-
@alice.messages.are_from(@bob).are_to(@alice).readed # all message from @bob to @alice and readed
|
96
|
-
@alice.deleted_messages.are_from(@bob) # all deleted messages from @bob
|
97
|
-
|
98
|
-
=== Delete message
|
99
|
-
|
100
|
-
@message = @alice.send_message(@bob, "Topic", "Body")
|
101
|
-
|
102
|
-
@alice.messages.process do |message|
|
103
|
-
message.delete
|
104
|
-
end
|
105
|
-
|
106
|
-
Now we can find message in trash
|
107
|
-
|
108
|
-
@alice.deleted_messages #=> [@message]
|
109
|
-
|
110
|
-
@alice.deleted_messages.process do |message|
|
111
|
-
message.delete
|
112
|
-
end
|
113
|
-
|
114
|
-
@alice.delete_message #=> []
|
115
|
-
|
116
|
-
Message was permanent delete
|
117
|
-
|
118
|
-
Copyright © 2011 Piotr Niełacny (http://ruby-blog.pl), released under the MIT license
|