• Stars
    star
    682
  • Rank 63,659 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 12 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Socialize your app with Likes, Follows and Mentions

Socialization

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.

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.

The Like feature works just like a Facebook Like. For example, John likes Pulp Fiction.

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).

Specs Gem Version

Installation

Add the gem to the gemfile: gem "socialization"

Run the generator: rails generate socialization -s

Or if you want to use Redis as your data store: rails generate socialization -s --store=redis

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.

Legacy Rails Support

This gem requires Rails 6 or better. Sorry!

Usage

Setup

Allow a model to be followed:

class Celebrity < ActiveRecord::Base
  ...
  acts_as_followable
  ...
end

Allow a model to be a follower:

class User < ActiveRecord::Base
  ...
  acts_as_follower
  ...
end

Allow a model to be liked:

class Movie < ActiveRecord::Base
  ...
  acts_as_likeable
  ...
end

Allow a model to like:

class User < ActiveRecord::Base
  ...
  acts_as_liker
  ...
end

Allow a model to be mentioned:

class User < ActiveRecord::Base
  ...
  acts_as_mentionable
  ...
end

Allow a model to mention:

class Comment < ActiveRecord::Base
  ...
  acts_as_mentioner
  ...
end

Or a more complex case where users can like and follow each other:

class User < ActiveRecord::Base
  ...
  acts_as_follower
  acts_as_followable
  acts_as_liker
  acts_as_likeable
  acts_as_mentionable
  ...
end

acts_as_follower Methods

Follow something

user.follow!(celebrity)

Stop following

user.unfollow!(celebrity)

Toggle

user.toggle_follow!(celebrity)

Is following?

user.follows?(celebrity)

What items are you following (given that an Item model is followed)?

user.followees(Item)

Number of followees (Requires followees_count column in db)

def change
  add_column :#{Table_name}, :followees_count, :integer, :default => 0
end

user.followees_count

acts_as_followable Methods

Find out if an objects follows

celebrity.followed_by?(user)

All followers

celebrity.followers(User)

Number of followers (Requires followers_count column in db)

def change
  add_column :#{Table_name}, :followers_count, :integer, :default => 0
end

celebrity.followers_count

acts_as_liker Methods

Like something

user.like!(movie)

Stop liking

user.unlike!(movie)

Toggle

user.toggle_like!(celebrity)

Likes?

user.likes?(movie)

Number of likees (Requires likees_count column in db)

def change
  add_column :#{Table_name}, :likees_count, :integer, :default => 0
end

user.likees_count

acts_as_likeable Methods

Find out if an objects likes

movie.liked_by?(user)

All likers

movie.likers(User)

Number of likers (Requires likers_count column in db)

def change
  add_column :#{Table_name}, :likers_count, :integer, :default => 0
end

movie.likers_count

acts_as_mentioner Methods

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.

Mention something

comment.mention!(user)

Remove mention

comment.unmention!(user)

Toggle

user.toggle_mention!(celebrity)

Mentions?

comment.mentions?(user)

All mentionees

comment.mentionees(User)

Number of mentionees (Requires mentionees column in db)

def change
  add_column :#{Table_name}, : mentionees, :integer, :default => 0
end

user. mentionees_count

acts_as_mentionable Methods

Find out if an objects mentions

user.mentioned_by?(comment)

All mentioners

user.mentioners(Comment)

Number of mentioners (Requires mentioners_count column in db)

def change
  add_column :#{Table_name}, :mentioners_count, :integer, :default => 0
end

movie.mentioners_count

Documentation

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.


Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Send me a pull request. Bonus points for topic branches.

Similar Projects

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.

Copyright

Copyright (c) 2012-2022 Carl Mercier -- Released under the MIT license.

More Repositories

1

gigabyte-z390-aorus-master-hackintosh

A guide to build your own Hackintosh based on Gigabyte Z390 Aorus Master
Ruby
476
star
2

ultimate_turbo_modal-rails

The ultimate Turbo / Stimulus / Hotwire modal window for Rails
Ruby
161
star
3

lg-tv-control-macos

Automatically wake/sleep and change the input of your LG TV when used as a monitor on macOS
Lua
104
star
4

shoestrap

A simple alternative to Chef and Puppet to bootstrap *nix machines.
Shell
53
star
5

solargraph-rails-init

A simple script to configure Solargraph to work with Rails
Ruby
32
star
6

git-p4-sync

Submit changes made to a Git repository into to Perforce
Ruby
22
star
7

scope_cache_key

Add cache_key functionality to ActiveRecord scopes
Ruby
21
star
8

sendyr

A Ruby interface for the wonderful e-mail newsletter application Sendy
Ruby
20
star
9

alfred-ticktick

Alfred workflow to add tasks to TickTick
Ruby
19
star
10

rails-assets-cdn

CDN support for Rails asset pipeline made easy
Ruby
18
star
11

nobspw

No Bullshit Password strength checker
Ruby
16
star
12

cacheable-csrf-token-rails

Cache HTML containing CSRF protection tokens without worrying
Ruby
15
star
13

ec2-extra-tools

A set of extra command line tools for Amazon EC2
14
star
14

unraid-sanity

A beautiful, sane theme for Unraid 6.6+
CSS
12
star
15

sanitization

Clean & sanitize your ActiveRecord data before saving to database
Ruby
12
star
16

pfsense-bulk-dhcp-import

Import DHCP static mapping from CSV to pfSense
Ruby
10
star
17

forever-internets

Automatically reboot your modem and router when your Internet crashes
Ruby
8
star
18

stimulus-reflex-invoice-beast

Beast-mode for invoice editing
Ruby
8
star
19

landscape

Dead simple server monitoring
Ruby
7
star
20

creality_ender5_config_and_notes

My Creality Ender 5 config files and notes for Marlin, Cura, Octoprint and others
C++
6
star
21

shoestrap-example

A simple Bash framework to bootstrap *nix machines without the headaches
Shell
6
star
22

spree-extra-variant

A Spree extension to add free-form text variants to products without having to create all the different possibilities in the database
JavaScript
6
star
23

postbin.rb

A PostBin.org clone written in Ruby/Sinatra
Ruby
5
star
24

abp_to_pihole_whitelist

AdBlock Plus to PiHole whitelist.txt converter
Ruby
4
star
25

ultimate_turbo_modal-demo

Demo application for Ultimate Turbo Modal for Rails
Ruby
4
star
26

docker-seafile

Shell
3
star
27

enumish

Database-backed Enum for ActiveRecord
Ruby
3
star
28

parsley-payment

Credit card validation for Parsley.js
2
star
29

ec2_userdata

A simple Ruby library that reads UserData on EC2 with graceful fallback when not running on EC2
Ruby
2
star
30

wordpress2tumblr

Import Wordpress posts, comments and images into Tumblr
Ruby
2
star
31

diff_dirs

Ruby helper to diff two directories
Ruby
2
star
32

email_transfer

Script that transfers emails from one server (POP or IMAP) to another (IMAP).
Python
2
star
33

ec2bundlr

EC2Bundlr is a simple and interactive Capistrano task to bundle an EC2 instance into an AMI (Amazon Machine Image)
Ruby
2
star
34

jquery-conditionaldom

ConditionalDom is a jQuery plugin that conditionally allows basic DOM manipulation
CoffeeScript
2
star
35

tplink_smarthome_api

A simple Ruby library to control TP-Link smart plugs
Ruby
2
star
36

cointracking_to_bitcointax

CoinTracking.info to Bitcoin.tax Converter
Ruby
2
star
37

beanstalk_watcher

A simple Sinatra app that monitors Beanstalkd tubes. Possibly to be used in conjunction with a monitoring package such as Monit.
Ruby
2
star
38

twitter_id

Tiny web application that finds the Twitter numeric ID when given a username
Ruby
1
star
39

daemonizr

Process forking and monitoring for mere mortals
1
star
40

validates_child_of

Performs validation on an ActiveRecord object to ensure that it is the child of another one.
Ruby
1
star
41

stimulus-controllers

A collection of useful Stimulus Controllers I wrote
JavaScript
1
star
42

this_person_does_not_exist

Ruby
1
star
43

interactive_brokers_2_tasty_works

Interactive Brokers to TastyWorks Trade Statement Converter in Ruby
Ruby
1
star
44

coin_tracking_rb

A Ruby client for CoinTracking.info
Ruby
1
star
45

karabiner-rules

1
star
46

clusty

No-nonsense EC2 instance and cluster launching
Ruby
1
star
47

awesome-osx

Fantastic software I use and love on macOS/OS X
1
star
48

acts_as_formatted

acts_as_formatted is a plugin that provides basic formatting capabilities to all ActiveRecord column objects of type :string or :text, as long as they have content (nil values will remain nil).
Ruby
1
star