facteur 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/.gitignore +23 -0
  2. data/CHANGELOG +4 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +115 -0
  5. data/LICENSE +20 -20
  6. data/README.markdown +135 -137
  7. data/Rakefile +19 -41
  8. data/lib/facteur.rb +25 -14
  9. data/lib/facteur/active_record_addressee_model.rb +12 -0
  10. data/lib/facteur/active_record_mailbox_model.rb +15 -0
  11. data/lib/facteur/active_record_message_model.rb +24 -0
  12. data/lib/facteur/addressee_model.rb +29 -130
  13. data/lib/facteur/base_addressee_model.rb +163 -0
  14. data/lib/facteur/mailbox.rb +16 -0
  15. data/lib/facteur/mailbox_model.rb +9 -6
  16. data/lib/facteur/message.rb +16 -0
  17. data/lib/facteur/message_model.rb +16 -16
  18. data/lib/facteur/mongoid_addressee_model.rb +12 -0
  19. data/lib/facteur/mongoid_mailbox_model.rb +18 -0
  20. data/lib/facteur/mongoid_message_model.rb +19 -0
  21. data/lib/facteur/version.rb +3 -0
  22. data/lib/generators/facteur/install/install_generator.rb +25 -28
  23. data/lib/generators/facteur/install/templates/create_mailboxes.rb +14 -14
  24. data/lib/generators/facteur/install/templates/create_messages.rb +19 -19
  25. data/spec/activerecord/activerecord_spec_helper.rb +11 -0
  26. data/spec/activerecord/facteur_spec.rb +47 -0
  27. data/spec/mongoid/facteur_spec.rb +49 -0
  28. data/spec/mongoid/mongoid_spec_helper.rb +11 -0
  29. data/spec/spec_helper.rb +10 -67
  30. data/spec/support/activerecord/schema.rb +32 -0
  31. data/spec/{facteur_spec.rb → support/facteur_examples.rb} +38 -49
  32. data/spec/support/mongoid/database.rb +12 -0
  33. metadata +139 -20
  34. data/.document +0 -5
  35. data/VERSION +0 -1
  36. data/lib/facteur/rails/tasks/facteur.rake +0 -13
  37. data/lib/generators/facteur/install/templates/mailbox.rb +0 -3
  38. data/lib/generators/facteur/install/templates/message.rb +0 -3
@@ -0,0 +1,23 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ spec/db/.*
23
+ *.gemspec
@@ -0,0 +1,4 @@
1
+ Version 1.3.0 (20.02.2011)
2
+ --------------------------
3
+ - Added mongoid support
4
+ - The mailbox and message models are now in the gem. They were removed from the generators
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in amistad.gemspec
4
+ gemspec
@@ -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) 2009 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.
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.
@@ -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
- Just run the following command :
8
-
9
- gem install facteur
10
-
11
- Then in your Gemfile add the following line :
12
-
13
- gem 'facteur'
14
-
15
- ## Usage ##
16
-
17
- First install the messaging system in your application :
18
-
19
- rails generate facteur:install
20
-
21
- This commands creates two new models called __mailbox__ and __message__ in *'app/models'* (in the future the names will be changeable):
22
-
23
- class Mailbox < ActiveRecord::Base
24
- include Facteur::MailboxModel
25
- end
26
-
27
- class Message < ActiveRecord::Base
28
- include Facteur::MessageModel
29
- end
30
-
31
- It also creates the migrations for the new models so don't forget to migrate your database :
32
-
33
- rake db:migrate
34
-
35
- Then to activate __facteur__ in your user model, just include the addressee's model as follows :
36
-
37
- class User < ActiveRecord::Base
38
- include Facteur::AddresseeModel
39
- end
40
-
41
- You model must be named 'User'. This will be changed in the future.
42
-
43
- ## Messaging system ##
44
-
45
- ### Creating mailboxes ###
46
-
47
- 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 :
48
-
49
- class User < ActiveRecord::Base
50
- include Facteur::AddresseeModel
51
-
52
- mailbox :private_mailbox, :default => true
53
- mailbox :public_mailbox
54
- end
55
-
56
- The previous example declare two mailboxes that will be created for each user. The mailboxes are created just after the user was created itself. Facteur generates for you two methods to access your mailboxes :
57
-
58
- # assuming that 'login' and 'password' are fields defined for the User model
59
- @john = User.create(:login => 'john', :password => 'pass')
60
-
61
- # Now, the mailboxes exist and they can be accessed
62
- @john.private_mailbox #=> returns the private mailbox
63
- @john.public_mailbox #=> returns the public mailbox
64
-
65
- # To check the mailboxes which where defined
66
- User.mailboxes #=> [{:name=>:private_mailbox, :default=>true}, {:name=>:public_mailbox}]
67
-
68
- It is also possible to create a mailbox dynamically. This mailbox will not be available to all the user but only to the user who created it :
69
-
70
- @john.create_mailbox(:new_mailbox) #=> true
71
- User.mailboxes #=> [{:name=>:private_mailbox, :default=>true}, {:name=>:public_mailbox}]
72
- @john.mailboxes #=> [{:name=>:private_mailbox, :default=>true}, {:name=>:public_mailbox}, {:name=>:new_mailbox}]
73
-
74
- 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.
75
-
76
- ### Sending messages ###
77
-
78
- It is possible to send a message to one or many user :
79
-
80
- @peter = User.create(:login => 'peter', :password => 'pass')
81
- @mary = User.create(:login => 'mary', :password => 'pass')
82
-
83
- @john.send_message('hello', :to => @peter, :in => :private_mailbox)
84
- @john.send_message('hello', :to => [@peter, @mary], :in => :public_mailbox)
85
-
86
- 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.
87
-
88
- You can access the messages in a mailbox :
89
-
90
- @peter.private_mailbox.messages
91
-
92
- To list the messages sent by a user :
93
-
94
- @john.messages_sent
95
-
96
- ### More methods ###
97
-
98
- This section list the other methods available for each elements of the messaging system :
99
-
100
- #### User ####
101
-
102
- mailboxes : mailboxes assigned to this user
103
- messages_sent : messages sent by the user
104
-
105
- #### Mailbox ####
106
-
107
- addressee : who the mailbox is assigned to
108
- messages : messages who are stored in the mailbox
109
- name : the name of the mailbox
110
-
111
- #### Message ####
112
-
113
- mailbox : mailbox where the message is stored
114
- author : user who send the message
115
- addressee : who the message was sent to
116
- body : body of the message
117
- created_at : date of creation
118
-
119
- ## Testing the gem ##
120
-
121
- It is possible to test facteur by running the following command from the gem directory:
122
-
123
- rake spec
124
-
125
- ## Note on Patches/Pull Requests ##
126
-
127
- * Fork the project.
128
- * Make your feature addition or bug fix.
129
- * Add tests for it. This is important so I don't break it in a
130
- future version unintentionally.
131
- * Commit, do not mess with rakefile, version, or history.
132
- (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)
133
- * Send me a pull request. Bonus points for topic branches.
134
-
135
- ## Copyright ##
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.