socialization 0.4.0 → 0.5.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. data/.gitignore +5 -1
  2. data/CHANGELOG.md +41 -0
  3. data/README.md +246 -0
  4. data/demo/{demo_app/.gitignore → .gitignore} +0 -0
  5. data/demo/{demo_app/Gemfile → Gemfile} +1 -1
  6. data/demo/{demo_app/README.rdoc → README.rdoc} +0 -0
  7. data/demo/{demo_app/Rakefile → Rakefile} +0 -0
  8. data/demo/{demo_app/app → app}/assets/images/rails.png +0 -0
  9. data/demo/{demo_app/app → app}/assets/javascripts/application.js +0 -0
  10. data/demo/{demo_app/app → app}/assets/stylesheets/application.css +0 -0
  11. data/demo/{demo_app/app → app}/controllers/application_controller.rb +0 -0
  12. data/demo/{demo_app/app → app}/helpers/application_helper.rb +0 -0
  13. data/demo/{demo_app/app → app}/mailers/.gitkeep +0 -0
  14. data/demo/{demo_app/app → app}/models/.gitkeep +0 -0
  15. data/demo/{demo_app/app → app}/models/celebrity.rb +0 -0
  16. data/demo/{demo_app/app → app}/models/comment.rb +0 -0
  17. data/demo/app/models/follow.rb +2 -0
  18. data/demo/app/models/like.rb +2 -0
  19. data/demo/app/models/mention.rb +2 -0
  20. data/demo/{demo_app/app → app}/models/movie.rb +0 -0
  21. data/demo/{demo_app/app → app}/models/user.rb +0 -0
  22. data/demo/{demo_app/app → app}/views/layouts/application.html.erb +0 -0
  23. data/demo/{demo_app/config.ru → config.ru} +0 -0
  24. data/demo/{demo_app/config → config}/application.rb +0 -0
  25. data/demo/{demo_app/config → config}/boot.rb +0 -0
  26. data/demo/{demo_app/config → config}/database.yml +0 -0
  27. data/demo/{demo_app/config → config}/environment.rb +0 -0
  28. data/demo/{demo_app/config → config}/environments/development.rb +0 -0
  29. data/demo/{demo_app/config → config}/environments/production.rb +0 -0
  30. data/demo/{demo_app/config → config}/environments/test.rb +0 -0
  31. data/demo/{demo_app/config → config}/initializers/backtrace_silencers.rb +0 -0
  32. data/demo/{demo_app/config → config}/initializers/inflections.rb +0 -0
  33. data/demo/{demo_app/config → config}/initializers/mime_types.rb +0 -0
  34. data/demo/{demo_app/config → config}/initializers/secret_token.rb +0 -0
  35. data/demo/{demo_app/config → config}/initializers/session_store.rb +1 -1
  36. data/demo/{demo_app/config → config}/initializers/wrap_parameters.rb +1 -1
  37. data/demo/{demo_app/config → config}/locales/en.yml +0 -0
  38. data/demo/{demo_app/config → config}/routes.rb +0 -0
  39. data/demo/{demo_app/db → db}/migrate/20120115051222_create_users.rb +0 -0
  40. data/demo/{demo_app/db → db}/migrate/20120115051234_create_movies.rb +0 -0
  41. data/demo/{demo_app/db → db}/migrate/20120115051255_create_celebrities.rb +0 -0
  42. data/demo/{demo_app/db → db}/migrate/20120115054646_create_follows.rb +0 -0
  43. data/demo/{demo_app/db → db}/migrate/20120115054647_create_likes.rb +0 -0
  44. data/demo/{demo_app/db → db}/migrate/20120221200644_create_mentions.rb +0 -0
  45. data/demo/{demo_app/db → db}/migrate/20120221202703_create_comments.rb +0 -0
  46. data/demo/{demo_app/db → db}/schema.rb +0 -1
  47. data/demo/{demo_app/db → db}/seeds.rb +0 -0
  48. data/demo/{demo_app/lib → lib}/assets/.gitkeep +0 -0
  49. data/demo/{demo_app/lib → lib}/tasks/.gitkeep +0 -0
  50. data/demo/{demo_app/public → public}/404.html +0 -0
  51. data/demo/{demo_app/public → public}/422.html +0 -0
  52. data/demo/{demo_app/public → public}/500.html +0 -0
  53. data/demo/{demo_app/public → public}/favicon.ico +0 -0
  54. data/demo/{demo_app/public → public}/index.html +0 -0
  55. data/demo/{demo_app/public → public}/robots.txt +0 -0
  56. data/demo/{demo_app/script → script}/rails +0 -0
  57. data/demo/{demo_app/test → test}/fixtures/.gitkeep +0 -0
  58. data/demo/{demo_app/test → test}/fixtures/celebrities.yml +0 -0
  59. data/demo/{demo_app/test → test}/fixtures/movies.yml +0 -0
  60. data/demo/{demo_app/test → test}/fixtures/users.yml +0 -0
  61. data/demo/{demo_app/test → test}/functional/.gitkeep +0 -0
  62. data/demo/{demo_app/test → test}/integration/.gitkeep +0 -0
  63. data/demo/{demo_app/test → test}/performance/browsing_test.rb +0 -0
  64. data/demo/{demo_app/test → test}/test_helper.rb +0 -0
  65. data/demo/{demo_app/test → test}/unit/.gitkeep +0 -0
  66. data/demo/{demo_app/test → test}/unit/celebrity_test.rb +0 -0
  67. data/demo/{demo_app/test → test}/unit/movie_test.rb +0 -0
  68. data/demo/{demo_app/test → test}/unit/user_test.rb +0 -0
  69. data/demo/{demo_app/vendor → vendor}/assets/javascripts/.gitkeep +0 -0
  70. data/demo/{demo_app/vendor → vendor}/assets/stylesheets/.gitkeep +0 -0
  71. data/demo/{demo_app/vendor → vendor}/plugins/.gitkeep +0 -0
  72. data/lib/generators/socialization/socialization_generator.rb +20 -9
  73. data/{generators/socialization/templates → lib/generators/socialization/templates/active_record}/migration_follows.rb +0 -0
  74. data/{generators/socialization/templates → lib/generators/socialization/templates/active_record}/migration_likes.rb +0 -0
  75. data/{generators/socialization/templates → lib/generators/socialization/templates/active_record}/migration_mentions.rb +0 -0
  76. data/lib/generators/socialization/templates/active_record/model_follow.rb +2 -0
  77. data/lib/generators/socialization/templates/active_record/model_like.rb +2 -0
  78. data/lib/generators/socialization/templates/active_record/model_mention.rb +2 -0
  79. data/lib/socialization.rb +3 -5
  80. data/lib/socialization/actors/follower.rb +74 -0
  81. data/lib/socialization/actors/liker.rb +74 -0
  82. data/lib/socialization/actors/mentioner.rb +74 -0
  83. data/lib/socialization/acts_as_helpers.rb +43 -0
  84. data/lib/socialization/config.rb +45 -0
  85. data/lib/socialization/helpers/string.rb +17 -0
  86. data/lib/socialization/stores/active_record/follow_store.rb +143 -0
  87. data/lib/socialization/stores/active_record/like_store.rb +143 -0
  88. data/lib/socialization/stores/active_record/mention_store.rb +143 -0
  89. data/lib/socialization/stores/redis/base.rb +8 -0
  90. data/lib/socialization/stores/redis/config.rb +11 -0
  91. data/lib/socialization/stores/redis/follow_store.rb +126 -0
  92. data/lib/socialization/stores/redis/like_store.rb +126 -0
  93. data/lib/socialization/stores/redis/mention_store.rb +126 -0
  94. data/lib/socialization/version.rb +1 -1
  95. data/lib/socialization/victims/followable.rb +38 -0
  96. data/lib/socialization/victims/likeable.rb +38 -0
  97. data/lib/socialization/victims/mentionable.rb +38 -0
  98. data/socialization.gemspec +3 -3
  99. data/test/actors/follower_test.rb +74 -0
  100. data/test/actors/liker_test.rb +74 -0
  101. data/test/actors/mentioner_test.rb +74 -0
  102. data/test/stores/active_record/follow_store_test.rb +121 -0
  103. data/test/stores/active_record/like_store_test.rb +121 -0
  104. data/test/stores/active_record/mention_store_test.rb +121 -0
  105. data/test/stores/redis/config_test.rb +30 -0
  106. data/test/stores/redis/follow_store_test.rb +153 -0
  107. data/test/stores/redis/like_store_test.rb +153 -0
  108. data/test/stores/redis/mention_store_test.rb +153 -0
  109. data/test/string_test.rb +13 -0
  110. data/test/test_helper.rb +70 -12
  111. data/test/victims/followable_test.rb +34 -0
  112. data/test/victims/likeable_test.rb +34 -0
  113. data/test/victims/mentionable_test.rb +34 -0
  114. data/test/world_test.rb +80 -69
  115. metadata +261 -176
  116. data/README.rdoc +0 -186
  117. data/demo/demo_app/app/models/follow.rb +0 -3
  118. data/demo/demo_app/app/models/like.rb +0 -3
  119. data/demo/demo_app/app/models/mention.rb +0 -3
  120. data/demo/demo_app/doc/README_FOR_APP +0 -2
  121. data/gemfiles/activerecord30.gemfile +0 -6
  122. data/gemfiles/activerecord30.gemfile.lock +0 -23
  123. data/gemfiles/activerecord31.gemfile +0 -6
  124. data/gemfiles/activerecord31.gemfile.lock +0 -25
  125. data/gemfiles/activerecord32.gemfile +0 -6
  126. data/gemfiles/activerecord32.gemfile.lock +0 -25
  127. data/generators/socialization/USAGE +0 -1
  128. data/generators/socialization/socialization_generator.rb +0 -15
  129. data/generators/socialization/templates/model_follow.rb +0 -3
  130. data/generators/socialization/templates/model_like.rb +0 -3
  131. data/generators/socialization/templates/model_mention.rb +0 -3
  132. data/lib/socialization/follow_store.rb +0 -14
  133. data/lib/socialization/followable.rb +0 -34
  134. data/lib/socialization/follower.rb +0 -50
  135. data/lib/socialization/hello.rb +0 -53
  136. data/lib/socialization/like_store.rb +0 -14
  137. data/lib/socialization/likeable.rb +0 -34
  138. data/lib/socialization/liker.rb +0 -54
  139. data/lib/socialization/mention_store.rb +0 -14
  140. data/lib/socialization/mentionable.rb +0 -36
  141. data/lib/socialization/mentioner.rb +0 -54
  142. data/test/follow_test.rb +0 -125
  143. data/test/like_test.rb +0 -125
  144. data/test/mention_test.rb +0 -116
data/.gitignore CHANGED
@@ -6,4 +6,8 @@ memory
6
6
  *.gem
7
7
  .rvmrc
8
8
  Gemfile.lock
9
- log
9
+ log
10
+ doc
11
+ .yardoc
12
+ .rbenv-version
13
+ gemfiles
data/CHANGELOG.md ADDED
@@ -0,0 +1,41 @@
1
+ # Changelog
2
+
3
+ ## 0.5.0.beta (June 6, 2012)
4
+
5
+ * **MAJOR REFACTORING:** Your Like, Follow and Mention models should now inherit the Socialization store base class instead of using the acts_as helper. (e.g.: class Follow < Socialization::ActiveRecordStores::FollowStore). See demo app for an example. Your code should be mostly unaffected.
6
+ * Changed: The persistence logic has now been moved to the Socialization::ActiveRecordStores namespace. More stores such as Redis or MongoDB can be easily added.
7
+ * Changed: `like!`, `follow!`, and `mention!` now return a boolean. True when the action was successful, false when it wasn't (e.g.: the relationship already exists).
8
+ * Changed: `unlike!`, `unfollow!` and `unmention!` will now return false if there is no record to destroy rather than raising `ActiveRecord::RecordNotFound`.
9
+ * Changed: Records can now like, follow or mention themselves. If you want to prevent this, it should be enforced directly in your application.
10
+ * Added: `toggle_like!`, `toggle_follow!` and `toggle_mention!` methods. Thanks to [@balvig](https://github.com/balvig).
11
+ * Added: support for single table inheritance. Thanks to [@balvig](https://github.com/balvig).
12
+
13
+ ## v0.4.0 (February 25, 2012)
14
+
15
+ * **BREAKING CHANGE:** Renamed `mentionner` to `mentioner`. This is proper English.
16
+ * Added: `followees`, `likees` and `mentionees` methods to `Follower`, `Liker` and `Mentioner`. Thanks to [@ihara2525](https://github.com/ihara2525).
17
+
18
+ ## v0.3.0 (February 22, 2012)
19
+
20
+ * **BREAKING CHANGE:** `likers`, `followers` now return a scope instead of an array. They also require to have the class of the desired scope as an argument. For example: `Movie.find(1).followers(User)`.
21
+ * Added: Mention support.
22
+ * Some refactoring and clean up. Thanks to [@tilsammans](https://github.com/tilsammans)
23
+
24
+
25
+ ## 0.2.2 (January 15, 2012)
26
+
27
+ * Improved tests.
28
+ * Changed: Can no longer like or follow yourself.
29
+
30
+ ## 0.2.1 (January 15, 2012)
31
+
32
+ * Bug fixes
33
+
34
+ ## 0.2.0 (January 15, 2012)
35
+
36
+ * Bug fixes
37
+ * Made Ruby 1.8.7 compatible
38
+
39
+ ## 0.1.0 (January 14, 2012)
40
+
41
+ * Initial release
data/README.md ADDED
@@ -0,0 +1,246 @@
1
+ # Socialization
2
+
3
+ Socialization is a Ruby Gem that allows any ActiveRecord model to `Follow`, `Like` and/or `Mention` any other model. ActiveRecord or Redis can be used as a data store.
4
+
5
+ The Follow feature is similar to Twitter's follow. For example, John follows Jane. Unlike Facebook's "friendship", Follow is a one-way concept. The fact that John follows Jane doesn't mean that Jane follows John.
6
+
7
+ The Like feature works just like a Facebook Like. For example, John likes Pulp Fiction.
8
+
9
+ The Mention feature was written with Facebook mentions in mind. For example, John mentions Jane in a comment. Typically, Jane would be highlighted in the comment user interface and possibly notified that John mentioned her. This Facebook feature is occasionally called Tagging, although tagging is generally something [entirely different](http://en.wikipedia.org/wiki/Tag_(metadata).
10
+
11
+ [![Build Status](https://secure.travis-ci.org/cmer/socialization.png?branch=master)](http://travis-ci.org/cmer/socialization)
12
+
13
+ ## Installation
14
+
15
+ ### Rails 3
16
+
17
+ Add the gem to the gemfile:
18
+ `gem "socialization"`
19
+
20
+ Run the generator:
21
+ `rails generate socialization -s`
22
+
23
+ Or if you want to use Redis as your data store:
24
+ `rails generate socialization -s --store=redis`
25
+
26
+ This will generate three migration files (when using ActiveRecord) and three models named Follow, Like and Mention. You may delete any of the Follow, Like or Mention models and migrations if you don't need that functionality in your application.
27
+
28
+ ### Rails 2.3.x Support
29
+
30
+ This gem requires Rails 3 or better. Sorry!
31
+
32
+ ## Usage
33
+
34
+ ### Setup
35
+
36
+ Allow a model to be followed:
37
+
38
+ class Celebrity < ActiveRecord::Base
39
+ ...
40
+ acts_as_followable
41
+ ...
42
+ end
43
+
44
+ Allow a model to be a follower:
45
+
46
+ class User < ActiveRecord::Base
47
+ ...
48
+ acts_as_follower
49
+ ...
50
+ end
51
+
52
+
53
+ Allow a model to be liked:
54
+
55
+ class Movie < ActiveRecord::Base
56
+ ...
57
+ acts_as_likeable
58
+ ...
59
+ end
60
+
61
+ Allow a model to like:
62
+
63
+ class User < ActiveRecord::Base
64
+ ...
65
+ acts_as_liker
66
+ ...
67
+ end
68
+
69
+ Allow a model to be mentioned:
70
+
71
+ class User < ActiveRecord::Base
72
+ ...
73
+ acts_as_mentionable
74
+ ...
75
+ end
76
+
77
+ Allow a model to mention:
78
+
79
+ class Comment < ActiveRecord::Base
80
+ ...
81
+ acts_as_mentioner
82
+ ...
83
+ end
84
+
85
+ Or a more complex case where users can like and follow each other:
86
+
87
+ class User < ActiveRecord::Base
88
+ ...
89
+ acts_as_follower
90
+ acts_as_followable
91
+ acts_as_liker
92
+ acts_as_likeable
93
+ acts_as_mentionable
94
+ ...
95
+ end
96
+
97
+ ***
98
+
99
+
100
+ ### acts_as_follower Methods
101
+
102
+ Follow something
103
+
104
+ user.follow!(celebrity)
105
+
106
+ Stop following
107
+
108
+ user.unfollow!(celebrity)
109
+
110
+ Toggle
111
+
112
+ user.toggle_follow!(celebrity)
113
+
114
+ Is following?
115
+
116
+ user.follows?(celebrity)
117
+
118
+
119
+ ***
120
+
121
+
122
+ ### acts_as_followable Methods
123
+
124
+ Find out if an objects follows
125
+
126
+ celebrity.followed_by?(user)
127
+
128
+ All followers
129
+
130
+ celebrity.followers(User)
131
+
132
+
133
+ ***
134
+
135
+
136
+ ### acts_as_liker Methods
137
+
138
+ Like something
139
+
140
+ user.like!(movie)
141
+
142
+ Stop liking
143
+
144
+ user.unlike!(movie)
145
+
146
+ Toggle
147
+
148
+ user.toggle_like!(celebrity)
149
+
150
+ Likes?
151
+
152
+ user.likes?(movie)
153
+
154
+ ***
155
+
156
+
157
+ ### acts_as_likeable Methods
158
+
159
+ Find out if an objects likes
160
+
161
+ movie.liked_by?(user)
162
+
163
+ All likers
164
+
165
+ movie.likers(User)
166
+
167
+ ***
168
+
169
+
170
+ ### acts_as_mentioner Methods
171
+
172
+ **Note that a "mentioner" is the object containing the mention and not necessarily the actor. For example, John mentions Jane in a comment. The mentioner is the comment object, NOT John.**
173
+
174
+ Mention something
175
+
176
+ comment.mention!(user)
177
+
178
+ Remove mention
179
+
180
+ comment.unmention!(user)
181
+
182
+ Toggle
183
+
184
+ user.toggle_mention!(celebrity)
185
+
186
+ Mentions?
187
+
188
+ comment.mentions?(user)
189
+
190
+
191
+ ***
192
+
193
+
194
+ ### acts_as_mentionable Methods
195
+
196
+ Find out if an objects mentions
197
+
198
+ user.mentioned_by?(comment)
199
+
200
+ All mentioners
201
+
202
+ user.mentioners(Comment)
203
+
204
+
205
+ ***
206
+
207
+
208
+ ## Documentation
209
+
210
+ You can find the compiled YARD documentation at http://rubydoc.info/github/cmer/socialization/frames. Documentation for methods inside `include` blocks is not currently generated although it exists in the code. A custom YARD filter needs to be written for YARD to pick those up.
211
+
212
+
213
+ ***
214
+
215
+ ## Changelog
216
+
217
+ Here it is: https://github.com/cmer/socialization/blob/master/CHANGELOG.md
218
+
219
+ ## Demo App
220
+
221
+ For your convenience, I have added a demo app in demo/demo_app. It does not have a web UI, but you can play with Socialization in the Rails console. It should also help you figure out hown to use Socialization in the Real World.
222
+
223
+ To use the demo app:
224
+
225
+ $ cd demo/demo_app
226
+ $ bundle
227
+ $ rake db:migrate
228
+ $ rake db:seed
229
+ $ rails console
230
+
231
+
232
+ ## Note on Patches/Pull Requests
233
+
234
+ * Fork the project.
235
+ * Make your feature addition or bug fix.
236
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
237
+ * Send me a pull request. Bonus points for topic branches.
238
+
239
+ ## Similar Projects
240
+
241
+ [acts_as_follower](https://github.com/tcocca/acts_as_follower) is a similar project that I only discovered when I was 95% finished writing the first version of Socialization. I initially intended to name this project acts_as_follower only to find out the name was taken. You might want to check it out as well so see which one suits your needs better. Socialization is simpler, supports "Likes" and "Mentions" and easilly extendable; acts_as_follower has more "Follow" features, however.
242
+
243
+
244
+ ## Copyright
245
+
246
+ Copyright (c) 2012 Carl Mercier -- Released under the MIT license.
File without changes
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 3.2.1'
4
- gem 'socialization'
4
+ gem 'socialization', :path => '../'
5
5
  # Bundle edge Rails instead:
6
6
  # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
7
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ class Follow < Socialization::ActiveRecordStores::FollowStore
2
+ end
@@ -0,0 +1,2 @@
1
+ class Like < Socialization::ActiveRecordStores::LikeStore
2
+ end
@@ -0,0 +1,2 @@
1
+ class Mention < Socialization::ActiveRecordStores::MentionStore
2
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,6 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- DemoApp::Application.config.session_store :cookie_store, key: '_demo_app_session'
3
+ DemoApp::Application.config.session_store :cookie_store, :key => '_demo_app_session'
4
4
 
5
5
  # Use the database for sessions instead of the cookie-based default,
6
6
  # which shouldn't be used to store highly confidential information
@@ -5,7 +5,7 @@
5
5
 
6
6
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
7
  ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters format: [:json]
8
+ wrap_parameters :format => [:json]
9
9
  end
10
10
 
11
11
  # Disable root element in JSON by default.
File without changes
File without changes
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
File without changes
File without changes
File without changes
File without changes