twrk-socialization 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/Appraisals +23 -0
- data/CHANGELOG.md +67 -0
- data/Gemfile +3 -0
- data/Guardfile +12 -0
- data/LICENSE +20 -0
- data/README.md +298 -0
- data/Rakefile +14 -0
- data/demo/.gitignore +15 -0
- data/demo/Gemfile +35 -0
- data/demo/README.rdoc +261 -0
- data/demo/Rakefile +7 -0
- data/demo/app/assets/images/rails.png +0 -0
- data/demo/app/assets/javascripts/application.js +15 -0
- data/demo/app/assets/stylesheets/application.css +13 -0
- data/demo/app/controllers/application_controller.rb +3 -0
- data/demo/app/helpers/application_helper.rb +2 -0
- data/demo/app/mailers/.gitkeep +0 -0
- data/demo/app/models/.gitkeep +0 -0
- data/demo/app/models/celebrity.rb +4 -0
- data/demo/app/models/comment.rb +5 -0
- data/demo/app/models/follow.rb +3 -0
- data/demo/app/models/like.rb +2 -0
- data/demo/app/models/mention.rb +2 -0
- data/demo/app/models/movie.rb +3 -0
- data/demo/app/models/user.rb +7 -0
- data/demo/app/views/layouts/application.html.erb +14 -0
- data/demo/config/application.rb +59 -0
- data/demo/config/boot.rb +6 -0
- data/demo/config/database.yml +25 -0
- data/demo/config/environment.rb +5 -0
- data/demo/config/environments/development.rb +37 -0
- data/demo/config/environments/production.rb +67 -0
- data/demo/config/environments/test.rb +37 -0
- data/demo/config/initializers/backtrace_silencers.rb +7 -0
- data/demo/config/initializers/inflections.rb +15 -0
- data/demo/config/initializers/mime_types.rb +5 -0
- data/demo/config/initializers/secret_token.rb +7 -0
- data/demo/config/initializers/session_store.rb +8 -0
- data/demo/config/initializers/wrap_parameters.rb +14 -0
- data/demo/config/locales/en.yml +5 -0
- data/demo/config/routes.rb +58 -0
- data/demo/config.ru +4 -0
- data/demo/db/migrate/20120115051222_create_users.rb +9 -0
- data/demo/db/migrate/20120115051234_create_movies.rb +9 -0
- data/demo/db/migrate/20120115051255_create_celebrities.rb +9 -0
- data/demo/db/migrate/20120115054646_create_follows.rb +14 -0
- data/demo/db/migrate/20120115054647_create_likes.rb +14 -0
- data/demo/db/migrate/20120221200644_create_mentions.rb +14 -0
- data/demo/db/migrate/20120221202703_create_comments.rb +9 -0
- data/demo/db/schema.rb +72 -0
- data/demo/db/seeds.rb +17 -0
- data/demo/lib/assets/.gitkeep +0 -0
- data/demo/lib/tasks/.gitkeep +0 -0
- data/demo/public/404.html +26 -0
- data/demo/public/422.html +26 -0
- data/demo/public/500.html +25 -0
- data/demo/public/favicon.ico +0 -0
- data/demo/public/index.html +204 -0
- data/demo/public/robots.txt +5 -0
- data/demo/script/rails +6 -0
- data/demo/test/fixtures/.gitkeep +0 -0
- data/demo/test/fixtures/celebrities.yml +7 -0
- data/demo/test/fixtures/movies.yml +7 -0
- data/demo/test/fixtures/users.yml +7 -0
- data/demo/test/functional/.gitkeep +0 -0
- data/demo/test/integration/.gitkeep +0 -0
- data/demo/test/performance/browsing_test.rb +12 -0
- data/demo/test/test_helper.rb +13 -0
- data/demo/test/unit/.gitkeep +0 -0
- data/demo/test/unit/celebrity_test.rb +7 -0
- data/demo/test/unit/movie_test.rb +7 -0
- data/demo/test/unit/user_test.rb +7 -0
- data/demo/vendor/assets/javascripts/.gitkeep +0 -0
- data/demo/vendor/assets/stylesheets/.gitkeep +0 -0
- data/demo/vendor/plugins/.gitkeep +0 -0
- data/init.rb +1 -0
- data/lib/generators/socialization/socialization_generator.rb +38 -0
- data/lib/generators/socialization/templates/active_record/migration_follows.rb +14 -0
- data/lib/generators/socialization/templates/active_record/migration_likes.rb +14 -0
- data/lib/generators/socialization/templates/active_record/migration_mentions.rb +14 -0
- data/lib/generators/socialization/templates/active_record/model_follow.rb +2 -0
- data/lib/generators/socialization/templates/active_record/model_like.rb +2 -0
- data/lib/generators/socialization/templates/active_record/model_mention.rb +2 -0
- data/lib/generators/socialization/templates/redis/model_follow.rb +2 -0
- data/lib/generators/socialization/templates/redis/model_like.rb +2 -0
- data/lib/generators/socialization/templates/redis/model_mention.rb +2 -0
- data/lib/socialization/actors/follower.rb +88 -0
- data/lib/socialization/actors/liker.rb +88 -0
- data/lib/socialization/actors/mentioner.rb +88 -0
- data/lib/socialization/config/config.rb +39 -0
- data/lib/socialization/helpers/acts_as_helpers.rb +39 -0
- data/lib/socialization/helpers/string.rb +17 -0
- data/lib/socialization/lib/exceptions.rb +3 -0
- data/lib/socialization/stores/active_record/follow.rb +125 -0
- data/lib/socialization/stores/active_record/like.rb +121 -0
- data/lib/socialization/stores/active_record/mention.rb +125 -0
- data/lib/socialization/stores/active_record/mixins/base.rb +12 -0
- data/lib/socialization/stores/mixins/base.rb +22 -0
- data/lib/socialization/stores/mixins/follow.rb +39 -0
- data/lib/socialization/stores/mixins/like.rb +40 -0
- data/lib/socialization/stores/mixins/mention.rb +40 -0
- data/lib/socialization/stores/redis/base.rb +125 -0
- data/lib/socialization/stores/redis/config.rb +11 -0
- data/lib/socialization/stores/redis/follow.rb +22 -0
- data/lib/socialization/stores/redis/like.rb +22 -0
- data/lib/socialization/stores/redis/mention.rb +22 -0
- data/lib/socialization/stores/redis/mixins/base.rb +8 -0
- data/lib/socialization/version.rb +3 -0
- data/lib/socialization/victims/followable.rb +50 -0
- data/lib/socialization/victims/likeable.rb +51 -0
- data/lib/socialization/victims/mentionable.rb +51 -0
- data/lib/socialization.rb +20 -0
- data/socialization.gemspec +32 -0
- data/spec/actors/follower_spec.rb +113 -0
- data/spec/actors/liker_spec.rb +105 -0
- data/spec/actors/mentioner_spec.rb +105 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/spec_support/data_stores.rb +232 -0
- data/spec/spec_support/matchers.rb +54 -0
- data/spec/stores/active_record/follow_store_spec.rb +147 -0
- data/spec/stores/active_record/like_store_spec.rb +146 -0
- data/spec/stores/active_record/mention_store_spec.rb +148 -0
- data/spec/stores/active_record/mixins/base_spec.rb +25 -0
- data/spec/stores/redis/base_spec.rb +195 -0
- data/spec/stores/redis/config_spec.rb +28 -0
- data/spec/stores/redis/follow_store_spec.rb +26 -0
- data/spec/stores/redis/like_store_spec.rb +23 -0
- data/spec/stores/redis/mention_store_spec.rb +23 -0
- data/spec/string_spec.rb +13 -0
- data/spec/victims/followable_spec.rb +59 -0
- data/spec/victims/likeable_spec.rb +58 -0
- data/spec/victims/mentionable_spec.rb +59 -0
- data/spec/world_spec.rb +107 -0
- metadata +322 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2150673a506b6d721aa076183f7ef5808857e8f5
|
4
|
+
data.tar.gz: f0b8e740ab91b10561b5a9a589675f742f09d8d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cbcda82d06d64f3b5bb7c3b7a963ebc3cf59d963bcbb181f18108f6619b6763b76fb09463515be583cb98b2c3c5e676423e3c9af2e701e8c7c610517832c8d4e
|
7
|
+
data.tar.gz: fce34142970e4e1510e9906175cb0c7e6aa3d513230d2f43876ed09ca4ed71e9ce48e03a1da05658985dd3b904e5d1166f85752a3cfcb97417d4a2acef50b5ba
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/.travis.yml
ADDED
data/Appraisals
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
appraise "activerecord30" do
|
2
|
+
gem "activerecord", "~> 3.0.10"
|
3
|
+
end
|
4
|
+
|
5
|
+
appraise "activerecord31" do
|
6
|
+
gem "activerecord", "~> 3.1.1"
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise "activerecord32" do
|
10
|
+
gem "activerecord", "~> 3.2.1"
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise "activerecord40" do
|
14
|
+
gem "activerecord", "~> 4.0.13"
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise "activerecord41" do
|
18
|
+
gem "activerecord", "~> 4.1.12"
|
19
|
+
end
|
20
|
+
|
21
|
+
appraise "activerecord42" do
|
22
|
+
gem "activerecord", "~> 4.2.3"
|
23
|
+
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 1.2 (August 8, 2015)
|
4
|
+
|
5
|
+
* Support for ActiveRecord counter caches (thanks @samnang)
|
6
|
+
* Moved entire test suite to RSpec
|
7
|
+
|
8
|
+
|
9
|
+
## 1.0.1 (January 8, 2014)
|
10
|
+
|
11
|
+
* Supports Rails 4 (thanks @thomas88)
|
12
|
+
* Dropping official support for Ruby 1.8.x, 1.9.2.
|
13
|
+
|
14
|
+
|
15
|
+
## 1.0.0 (May 29, 2013)
|
16
|
+
|
17
|
+
* Same as 0.5.0.beta4. Been using it in a very high traffic production environment for over a year and it works.
|
18
|
+
|
19
|
+
|
20
|
+
## 0.5.0.beta (June 6, 2012)
|
21
|
+
|
22
|
+
* **IMPORTANT:** This release includes many changes, some breaking. Make sure to test your code carefully after upgrading.
|
23
|
+
* **BREAKING CHANGE:** 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::Follow). See demo app for an example.
|
24
|
+
* **BREAKING CHANGE:** the `followers`, `followables` etc methods now return an array of objects. Use methods such as `followers_relation` for an ActiveRecord::Relation.
|
25
|
+
* Changed: The persistence logic has now been moved to the Socialization::ActiveRecordStores namespace. More stores can be easily added.
|
26
|
+
* 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).
|
27
|
+
* Changed: `unlike!`, `unfollow!` and `unmention!` will now return false if there is no record to destroy rather than raising `ActiveRecord::RecordNotFound`.
|
28
|
+
* Changed: Records can now like, follow or mention themselves. If you want to prevent this, it should be enforced directly in your application.
|
29
|
+
* Added: Data can now be stored in Redis.
|
30
|
+
* Added: `toggle_like!`, `toggle_follow!` and `toggle_mention!` methods. Thanks to [@balvig](https://github.com/balvig).
|
31
|
+
* Added: support for single table inheritance. Thanks to [@balvig](https://github.com/balvig).
|
32
|
+
* Changed: raises Socialization::ArgumentError instead of ::ArgumentError
|
33
|
+
|
34
|
+
|
35
|
+
## v0.4.0 (February 25, 2012)
|
36
|
+
|
37
|
+
* **BREAKING CHANGE:** Renamed `mentionner` to `mentioner`. This is proper English.
|
38
|
+
* Added: `followees`, `likees` and `mentionees` methods to `Follower`, `Liker` and `Mentioner`. Thanks to [@ihara2525](https://github.com/ihara2525).
|
39
|
+
|
40
|
+
|
41
|
+
## v0.3.0 (February 22, 2012)
|
42
|
+
|
43
|
+
* **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)`.
|
44
|
+
* Added: Mention support.
|
45
|
+
* Some refactoring and clean up. Thanks to [@tilsammans](https://github.com/tilsammans)
|
46
|
+
|
47
|
+
|
48
|
+
## 0.2.2 (January 15, 2012)
|
49
|
+
|
50
|
+
* Improved tests.
|
51
|
+
* Changed: Can no longer like or follow yourself.
|
52
|
+
|
53
|
+
|
54
|
+
## 0.2.1 (January 15, 2012)
|
55
|
+
|
56
|
+
* Bug fixes
|
57
|
+
|
58
|
+
|
59
|
+
## 0.2.0 (January 15, 2012)
|
60
|
+
|
61
|
+
* Bug fixes
|
62
|
+
* Made Ruby 1.8.7 compatible
|
63
|
+
|
64
|
+
|
65
|
+
## 0.1.0 (January 14, 2012)
|
66
|
+
|
67
|
+
* Initial release
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
2
|
+
require "guard/rspec/dsl"
|
3
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
+
|
5
|
+
rspec = dsl.rspec
|
6
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
7
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
8
|
+
watch(%r{^spec/.+_spec\.rb$})
|
9
|
+
|
10
|
+
ruby = dsl.ruby
|
11
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
12
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Carl Mercier
|
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.md
ADDED
@@ -0,0 +1,298 @@
|
|
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/4
|
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
|
+
What items are you following (given that an Item model is followed)?
|
119
|
+
|
120
|
+
user.followees(Item)
|
121
|
+
|
122
|
+
Number of followees (Requires followees_count column in db)
|
123
|
+
|
124
|
+
def change
|
125
|
+
add_column :#{Table_name}, :followees_count, :integer, :default => 0
|
126
|
+
end
|
127
|
+
|
128
|
+
user.followees_count
|
129
|
+
|
130
|
+
***
|
131
|
+
|
132
|
+
|
133
|
+
### acts_as_followable Methods
|
134
|
+
|
135
|
+
Find out if an objects follows
|
136
|
+
|
137
|
+
celebrity.followed_by?(user)
|
138
|
+
|
139
|
+
All followers
|
140
|
+
|
141
|
+
celebrity.followers(User)
|
142
|
+
|
143
|
+
Number of followers (Requires followers_count column in db)
|
144
|
+
|
145
|
+
def change
|
146
|
+
add_column :#{Table_name}, :followers_count, :integer, :default => 0
|
147
|
+
end
|
148
|
+
|
149
|
+
celebrity.followers_count
|
150
|
+
|
151
|
+
***
|
152
|
+
|
153
|
+
|
154
|
+
### acts_as_liker Methods
|
155
|
+
|
156
|
+
Like something
|
157
|
+
|
158
|
+
user.like!(movie)
|
159
|
+
|
160
|
+
Stop liking
|
161
|
+
|
162
|
+
user.unlike!(movie)
|
163
|
+
|
164
|
+
Toggle
|
165
|
+
|
166
|
+
user.toggle_like!(celebrity)
|
167
|
+
|
168
|
+
Likes?
|
169
|
+
|
170
|
+
user.likes?(movie)
|
171
|
+
|
172
|
+
Number of likees (Requires likees_count column in db)
|
173
|
+
|
174
|
+
def change
|
175
|
+
add_column :#{Table_name}, :likees_count, :integer, :default => 0
|
176
|
+
end
|
177
|
+
|
178
|
+
user.likees_count
|
179
|
+
|
180
|
+
***
|
181
|
+
|
182
|
+
|
183
|
+
### acts_as_likeable Methods
|
184
|
+
|
185
|
+
Find out if an objects likes
|
186
|
+
|
187
|
+
movie.liked_by?(user)
|
188
|
+
|
189
|
+
All likers
|
190
|
+
|
191
|
+
movie.likers(User)
|
192
|
+
|
193
|
+
Number of likers (Requires likers_count column in db)
|
194
|
+
|
195
|
+
def change
|
196
|
+
add_column :#{Table_name}, :likers_count, :integer, :default => 0
|
197
|
+
end
|
198
|
+
|
199
|
+
movie.likers_count
|
200
|
+
|
201
|
+
***
|
202
|
+
|
203
|
+
|
204
|
+
### acts_as_mentioner Methods
|
205
|
+
|
206
|
+
**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.**
|
207
|
+
|
208
|
+
Mention something
|
209
|
+
|
210
|
+
comment.mention!(user)
|
211
|
+
|
212
|
+
Remove mention
|
213
|
+
|
214
|
+
comment.unmention!(user)
|
215
|
+
|
216
|
+
Toggle
|
217
|
+
|
218
|
+
user.toggle_mention!(celebrity)
|
219
|
+
|
220
|
+
Mentions?
|
221
|
+
|
222
|
+
comment.mentions?(user)
|
223
|
+
|
224
|
+
All mentionees
|
225
|
+
|
226
|
+
comment.mentionees(User)
|
227
|
+
|
228
|
+
Number of mentionees (Requires mentionees column in db)
|
229
|
+
|
230
|
+
def change
|
231
|
+
add_column :#{Table_name}, : mentionees, :integer, :default => 0
|
232
|
+
end
|
233
|
+
|
234
|
+
user. mentionees_count
|
235
|
+
|
236
|
+
***
|
237
|
+
|
238
|
+
|
239
|
+
### acts_as_mentionable Methods
|
240
|
+
|
241
|
+
Find out if an objects mentions
|
242
|
+
|
243
|
+
user.mentioned_by?(comment)
|
244
|
+
|
245
|
+
All mentioners
|
246
|
+
|
247
|
+
user.mentioners(Comment)
|
248
|
+
|
249
|
+
Number of mentioners (Requires mentioners_count column in db)
|
250
|
+
|
251
|
+
def change
|
252
|
+
add_column :#{Table_name}, :mentioners_count, :integer, :default => 0
|
253
|
+
end
|
254
|
+
|
255
|
+
movie.mentioners_count
|
256
|
+
|
257
|
+
***
|
258
|
+
|
259
|
+
|
260
|
+
## Documentation
|
261
|
+
|
262
|
+
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.
|
263
|
+
|
264
|
+
|
265
|
+
***
|
266
|
+
|
267
|
+
## Changelog
|
268
|
+
|
269
|
+
Here it is: https://github.com/cmer/socialization/blob/master/CHANGELOG.md
|
270
|
+
|
271
|
+
## Demo App
|
272
|
+
|
273
|
+
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.
|
274
|
+
|
275
|
+
To use the demo app:
|
276
|
+
|
277
|
+
$ cd demo/demo_app
|
278
|
+
$ bundle
|
279
|
+
$ rake db:migrate
|
280
|
+
$ rake db:seed
|
281
|
+
$ rails console
|
282
|
+
|
283
|
+
|
284
|
+
## Note on Patches/Pull Requests
|
285
|
+
|
286
|
+
* Fork the project.
|
287
|
+
* Make your feature addition or bug fix.
|
288
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
289
|
+
* Send me a pull request. Bonus points for topic branches.
|
290
|
+
|
291
|
+
## Similar Projects
|
292
|
+
|
293
|
+
[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.
|
294
|
+
|
295
|
+
|
296
|
+
## Copyright
|
297
|
+
|
298
|
+
Copyright (c) 2012-2015 Carl Mercier -- Released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'appraisal'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
desc 'Default: run unit tests against all supported versions of ActiveRecord'
|
10
|
+
task :default => ["appraisal:install"] do |t|
|
11
|
+
exec("rake appraisal spec")
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
end
|
data/demo/.gitignore
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile ~/.gitignore_global
|
6
|
+
|
7
|
+
# Ignore bundler config
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
|
13
|
+
# Ignore all logfiles and tempfiles.
|
14
|
+
/log/*.log
|
15
|
+
/tmp
|
data/demo/Gemfile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 3.2.1'
|
4
|
+
gem 'socialization', :path => '../'
|
5
|
+
# Bundle edge Rails instead:
|
6
|
+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
7
|
+
|
8
|
+
gem 'sqlite3'
|
9
|
+
|
10
|
+
|
11
|
+
# Gems used only for assets and not required
|
12
|
+
# in production environments by default.
|
13
|
+
group :assets do
|
14
|
+
gem 'sass-rails', '~> 3.2.3'
|
15
|
+
gem 'coffee-rails', '~> 3.2.0'
|
16
|
+
|
17
|
+
gem 'uglifier', '>= 1.0.3'
|
18
|
+
end
|
19
|
+
|
20
|
+
gem 'jquery-rails'
|
21
|
+
|
22
|
+
# To use ActiveModel has_secure_password
|
23
|
+
# gem 'bcrypt-ruby', '~> 3.0.0'
|
24
|
+
|
25
|
+
# To use Jbuilder templates for JSON
|
26
|
+
# gem 'jbuilder'
|
27
|
+
|
28
|
+
# Use unicorn as the web server
|
29
|
+
# gem 'unicorn'
|
30
|
+
|
31
|
+
# Deploy with Capistrano
|
32
|
+
# gem 'capistrano'
|
33
|
+
|
34
|
+
# To use debugger
|
35
|
+
# gem 'ruby-debug19', :require => 'ruby-debug'
|