facteur 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +23 -0
- data/CHANGELOG +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +115 -0
- data/LICENSE +20 -20
- data/README.markdown +135 -137
- data/Rakefile +19 -41
- data/lib/facteur.rb +25 -14
- data/lib/facteur/active_record_addressee_model.rb +12 -0
- data/lib/facteur/active_record_mailbox_model.rb +15 -0
- data/lib/facteur/active_record_message_model.rb +24 -0
- data/lib/facteur/addressee_model.rb +29 -130
- data/lib/facteur/base_addressee_model.rb +163 -0
- data/lib/facteur/mailbox.rb +16 -0
- data/lib/facteur/mailbox_model.rb +9 -6
- data/lib/facteur/message.rb +16 -0
- data/lib/facteur/message_model.rb +16 -16
- data/lib/facteur/mongoid_addressee_model.rb +12 -0
- data/lib/facteur/mongoid_mailbox_model.rb +18 -0
- data/lib/facteur/mongoid_message_model.rb +19 -0
- data/lib/facteur/version.rb +3 -0
- data/lib/generators/facteur/install/install_generator.rb +25 -28
- data/lib/generators/facteur/install/templates/create_mailboxes.rb +14 -14
- data/lib/generators/facteur/install/templates/create_messages.rb +19 -19
- data/spec/activerecord/activerecord_spec_helper.rb +11 -0
- data/spec/activerecord/facteur_spec.rb +47 -0
- data/spec/mongoid/facteur_spec.rb +49 -0
- data/spec/mongoid/mongoid_spec_helper.rb +11 -0
- data/spec/spec_helper.rb +10 -67
- data/spec/support/activerecord/schema.rb +32 -0
- data/spec/{facteur_spec.rb → support/facteur_examples.rb} +38 -49
- data/spec/support/mongoid/database.rb +12 -0
- metadata +139 -20
- data/.document +0 -5
- data/VERSION +0 -1
- data/lib/facteur/rails/tasks/facteur.rake +0 -13
- data/lib/generators/facteur/install/templates/mailbox.rb +0 -3
- data/lib/generators/facteur/install/templates/message.rb +0 -3
data/.gitignore
ADDED
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
facteur (1.3.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
abstract (1.0.0)
|
10
|
+
actionmailer (3.0.7)
|
11
|
+
actionpack (= 3.0.7)
|
12
|
+
mail (~> 2.2.15)
|
13
|
+
actionpack (3.0.7)
|
14
|
+
activemodel (= 3.0.7)
|
15
|
+
activesupport (= 3.0.7)
|
16
|
+
builder (~> 2.1.2)
|
17
|
+
erubis (~> 2.6.6)
|
18
|
+
i18n (~> 0.5.0)
|
19
|
+
rack (~> 1.2.1)
|
20
|
+
rack-mount (~> 0.6.14)
|
21
|
+
rack-test (~> 0.5.7)
|
22
|
+
tzinfo (~> 0.3.23)
|
23
|
+
activemodel (3.0.7)
|
24
|
+
activesupport (= 3.0.7)
|
25
|
+
builder (~> 2.1.2)
|
26
|
+
i18n (~> 0.5.0)
|
27
|
+
activerecord (3.0.7)
|
28
|
+
activemodel (= 3.0.7)
|
29
|
+
activesupport (= 3.0.7)
|
30
|
+
arel (~> 2.0.2)
|
31
|
+
tzinfo (~> 0.3.23)
|
32
|
+
activeresource (3.0.7)
|
33
|
+
activemodel (= 3.0.7)
|
34
|
+
activesupport (= 3.0.7)
|
35
|
+
activesupport (3.0.7)
|
36
|
+
arel (2.0.9)
|
37
|
+
awesome_print (0.3.2)
|
38
|
+
bson (1.3.0)
|
39
|
+
bson_ext (1.3.0)
|
40
|
+
builder (2.1.2)
|
41
|
+
chalofa_ruby-progressbar (0.0.9.1)
|
42
|
+
diff-lcs (1.1.2)
|
43
|
+
erubis (2.6.6)
|
44
|
+
abstract (>= 1.0.0)
|
45
|
+
fuubar (0.0.4)
|
46
|
+
chalofa_ruby-progressbar (~> 0.0.9)
|
47
|
+
rspec (~> 2.0)
|
48
|
+
rspec-instafail (~> 0.1.4)
|
49
|
+
i18n (0.5.0)
|
50
|
+
mail (2.2.17)
|
51
|
+
activesupport (>= 2.3.6)
|
52
|
+
i18n (>= 0.4.0)
|
53
|
+
mime-types (~> 1.16)
|
54
|
+
treetop (~> 1.4.8)
|
55
|
+
mime-types (1.16)
|
56
|
+
mongo (1.3.0)
|
57
|
+
bson (>= 1.3.0)
|
58
|
+
mongoid (2.0.1)
|
59
|
+
activemodel (~> 3.0)
|
60
|
+
mongo (~> 1.3)
|
61
|
+
tzinfo (~> 0.3.22)
|
62
|
+
will_paginate (~> 3.0.pre)
|
63
|
+
polyglot (0.3.1)
|
64
|
+
rack (1.2.2)
|
65
|
+
rack-mount (0.6.14)
|
66
|
+
rack (>= 1.0.0)
|
67
|
+
rack-test (0.5.7)
|
68
|
+
rack (>= 1.0)
|
69
|
+
rails (3.0.7)
|
70
|
+
actionmailer (= 3.0.7)
|
71
|
+
actionpack (= 3.0.7)
|
72
|
+
activerecord (= 3.0.7)
|
73
|
+
activeresource (= 3.0.7)
|
74
|
+
activesupport (= 3.0.7)
|
75
|
+
bundler (~> 1.0)
|
76
|
+
railties (= 3.0.7)
|
77
|
+
railties (3.0.7)
|
78
|
+
actionpack (= 3.0.7)
|
79
|
+
activesupport (= 3.0.7)
|
80
|
+
rake (>= 0.8.7)
|
81
|
+
thor (~> 0.14.4)
|
82
|
+
rake (0.8.7)
|
83
|
+
rspec (2.5.0)
|
84
|
+
rspec-core (~> 2.5.0)
|
85
|
+
rspec-expectations (~> 2.5.0)
|
86
|
+
rspec-mocks (~> 2.5.0)
|
87
|
+
rspec-core (2.5.1)
|
88
|
+
rspec-expectations (2.5.0)
|
89
|
+
diff-lcs (~> 1.1.2)
|
90
|
+
rspec-instafail (0.1.7)
|
91
|
+
rspec-mocks (2.5.0)
|
92
|
+
sqlite3 (1.3.3)
|
93
|
+
sqlite3 (1.3.3-x86-mingw32)
|
94
|
+
thor (0.14.6)
|
95
|
+
treetop (1.4.9)
|
96
|
+
polyglot (>= 0.3.1)
|
97
|
+
tzinfo (0.3.26)
|
98
|
+
will_paginate (3.0.pre2)
|
99
|
+
|
100
|
+
PLATFORMS
|
101
|
+
ruby
|
102
|
+
x86-mingw32
|
103
|
+
|
104
|
+
DEPENDENCIES
|
105
|
+
activerecord (~> 3.0.7)
|
106
|
+
activesupport (~> 3.0.7)
|
107
|
+
awesome_print (~> 0.3.2)
|
108
|
+
bson_ext (~> 1.3)
|
109
|
+
bundler (~> 1.0.12)
|
110
|
+
facteur!
|
111
|
+
fuubar (~> 0.0.4)
|
112
|
+
mongoid (~> 2.0.0)
|
113
|
+
rails (~> 3.0.7)
|
114
|
+
rspec (~> 2.5.0)
|
115
|
+
sqlite3 (>= 1.3.2)
|
data/LICENSE
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright (c)
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2011 Rawane ZOSSOU
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
CHANGED
@@ -1,137 +1,135 @@
|
|
1
|
-
# facteur #
|
2
|
-
|
3
|
-
Facteur allows you to add an email-like messaging system in your Rails 3 application. You can create many mailboxes for your users where they will be able to send and receive messages.
|
4
|
-
|
5
|
-
## Installation ##
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
gem
|
10
|
-
|
11
|
-
Then
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
## Usage ##
|
16
|
-
|
17
|
-
First install the messaging system in your application :
|
18
|
-
|
19
|
-
rails generate facteur:install
|
20
|
-
|
21
|
-
This commands creates
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
class
|
28
|
-
include Facteur::
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
#
|
59
|
-
@john
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
@
|
81
|
-
@
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
*
|
128
|
-
|
129
|
-
*
|
130
|
-
|
131
|
-
*
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
Copyright (c) 2010 Rawane ZOSSOU. See LICENSE for details.
|
1
|
+
# facteur #
|
2
|
+
|
3
|
+
Facteur allows you to add an email-like messaging system in your Rails 3 application. You can create many mailboxes for your users where they will be able to send and receive messages. Facteur supports ActiverRecord 3.0.x and Mongoid 2.0.x.
|
4
|
+
|
5
|
+
## Installation ##
|
6
|
+
|
7
|
+
In your Gemfile add the following line :
|
8
|
+
|
9
|
+
gem 'facteur'
|
10
|
+
|
11
|
+
Then run the following command:
|
12
|
+
|
13
|
+
bundle install
|
14
|
+
|
15
|
+
## Usage ##
|
16
|
+
|
17
|
+
First install the messaging system in your application :
|
18
|
+
|
19
|
+
rails generate facteur:install
|
20
|
+
|
21
|
+
This commands creates the migrations which creates the tables we need so don't forget to migrate your database :
|
22
|
+
|
23
|
+
rake db:migrate
|
24
|
+
|
25
|
+
Then to activate __facteur__ in your user model, just include the addressee's model as follows :
|
26
|
+
|
27
|
+
class User < ActiveRecord::Base
|
28
|
+
include Facteur::AddresseeModel
|
29
|
+
end
|
30
|
+
|
31
|
+
or
|
32
|
+
|
33
|
+
class User
|
34
|
+
include Mongoid::Document
|
35
|
+
include Facteur::AddresseeModel
|
36
|
+
end
|
37
|
+
|
38
|
+
You model must be named 'User'. This will be changed in the future.
|
39
|
+
|
40
|
+
## Messaging system ##
|
41
|
+
|
42
|
+
### Creating mailboxes ###
|
43
|
+
|
44
|
+
In the facteur's system, each user must have a mailbox where he can receive messages. The mailboxes can be declared statically and/or dynamically. Let's start first by the static way :
|
45
|
+
|
46
|
+
class User < ActiveRecord::Base
|
47
|
+
include Facteur::AddresseeModel
|
48
|
+
|
49
|
+
mailbox :private_mailbox, :default => true
|
50
|
+
mailbox :public_mailbox
|
51
|
+
end
|
52
|
+
|
53
|
+
The previous example declare two mailboxes that will be created for each user. The mailboxes are created when they are first accessed. Facteur generates for you two methods to access your mailboxes :
|
54
|
+
|
55
|
+
# assuming that 'login' and 'password' are fields defined for the User model
|
56
|
+
@john = User.create(:login => 'john', :password => 'pass')
|
57
|
+
|
58
|
+
# Now, the mailboxes exist and they can be accessed
|
59
|
+
@john.private_mailbox #=> generates and returns the private mailbox
|
60
|
+
@john.public_mailbox #=> generates and returns the public mailbox
|
61
|
+
|
62
|
+
# To check the mailboxes which where defined
|
63
|
+
User.mailboxes #=> [{:name=>:private_mailbox, :default=>true}, {:name=>:public_mailbox}]
|
64
|
+
|
65
|
+
It is also possible to create a mailbox dynamically. This mailbox will not be available for all the users but only for the user who created it :
|
66
|
+
|
67
|
+
@john.create_mailbox(:new_mailbox) #=> true
|
68
|
+
User.mailboxes #=> [{:name=>:private_mailbox, :default=>true}, {:name=>:public_mailbox}]
|
69
|
+
@john.mailboxes #=> [{:name=>:private_mailbox, :default=>true}, {:name=>:public_mailbox}, {:name=>:new_mailbox}]
|
70
|
+
|
71
|
+
After the previous example, the "news\_mailbox" is only avalaible to John. The names of the mailboxes must be unique. if you try to create a mailbox which already exists, the create_mailbox() method will return false.
|
72
|
+
|
73
|
+
### Sending messages ###
|
74
|
+
|
75
|
+
It is possible to send a message to one or many user :
|
76
|
+
|
77
|
+
@peter = User.create(:login => 'peter', :password => 'pass')
|
78
|
+
@mary = User.create(:login => 'mary', :password => 'pass')
|
79
|
+
|
80
|
+
@john.send_message('hello', :to => @peter, :in => :private_mailbox)
|
81
|
+
@john.send_message('hello', :to => [@peter, @mary], :in => :public_mailbox)
|
82
|
+
|
83
|
+
The 'in' option is not mandatory. If it is not given, the message is delivered to the default mailbox. If there is no default mailbox defined then the method fails.
|
84
|
+
|
85
|
+
You can access the messages in a mailbox :
|
86
|
+
|
87
|
+
@peter.private_mailbox.messages
|
88
|
+
|
89
|
+
To list the messages sent by a user :
|
90
|
+
|
91
|
+
@john.sent_messages
|
92
|
+
|
93
|
+
### More methods ###
|
94
|
+
|
95
|
+
This section list the other methods available for each elements of the messaging system :
|
96
|
+
|
97
|
+
#### User ####
|
98
|
+
|
99
|
+
mailboxes : mailboxes assigned to this user
|
100
|
+
sent_messages : messages sent by the user
|
101
|
+
|
102
|
+
#### Mailbox ####
|
103
|
+
|
104
|
+
addressee : who the mailbox is assigned to
|
105
|
+
messages : messages who are stored in the mailbox
|
106
|
+
name : the name of the mailbox
|
107
|
+
|
108
|
+
#### Message ####
|
109
|
+
|
110
|
+
mailbox : mailbox where the message is stored
|
111
|
+
author : user who send the message
|
112
|
+
addressees : who the message was sent to
|
113
|
+
body : body of the message
|
114
|
+
subject : subject of the message
|
115
|
+
created_at : date of creation
|
116
|
+
|
117
|
+
## Testing the gem ##
|
118
|
+
|
119
|
+
It is possible to test facteur by running the following command from the gem directory:
|
120
|
+
|
121
|
+
rake spec
|
122
|
+
|
123
|
+
## Note on Patches/Pull Requests ##
|
124
|
+
|
125
|
+
* Fork the project.
|
126
|
+
* Make your feature addition or bug fix.
|
127
|
+
* Add tests for it. This is important so I don't break it in a
|
128
|
+
future version unintentionally.
|
129
|
+
* Commit, do not mess with rakefile, version, or history.
|
130
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
131
|
+
* Send me a pull request. Bonus points for topic branches.
|
132
|
+
|
133
|
+
## Copyright ##
|
134
|
+
|
135
|
+
Copyright (c) 2011 Rawane ZOSSOU. See LICENSE for details.
|