Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Use Redis to make your Ruby objects Likeable

tree: 1b9062f8ed

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 autotest Initial Import of Likeable Redis October 11, 2011
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .autotest Initial Import of Likeable Redis October 11, 2011
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec Initial Import of Likeable Redis October 11, 2011
Octocat-spinner-32 .rvmrc
Octocat-spinner-32 Gemfile
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 license.txt Initial Import of Likeable Redis October 11, 2011
README.md

Use Redis to Make your Ruby objects Likeable!

You like this

Likeable is the easiest way to allow your models to be liked by users, just drop a few lines of code into your model and you're good to go.

    class Comment
      attr_accessor :id

      # ...
    end

    Likeable.setup do |likeable|
      likeable.classes = [Comment]
      likeable.redis   = Redis.new
    end

    comment = Comment.find(15)
    comment.like_count                  # => 0
    current_user.like!(comment)         # => #<Likeable::Like ... >
    comment.like_count                  # => 1
    comment.likes                       # => [#<Likeable::Like ... >]
    comment.likes.last.user             # => #<User ... >
    comment.likes.last.created_at       # => Wed Jul 27 19:34:32 -0500 2011

    comment.liked_by?(current_user)     # => true

    current_user.all_liked(Comment)     # => [#<Comment ...>, ...]

Setup

Gemfile:

gem 'Likeable'

Next set up your Redis connection and specify models to like in initializers/likeable.rb:

    Likeable.setup do |likeable|
      likeable.classes = [Comment, Spot]
      likeable.redis   = Redis.new
    end

Thats about it.

           RedisRed            RedisRedi
        RedisRedisRedi       RedisRedisRedisR
      RedisRedisRedisRedi   RedisRedisRedisRedi
     RedisRedisRedisRedisRedisRedisRe       Redi
    RedisRedisRedisRedisRedisRedisRe         Redi
   RedisRedisRedisRedisRedisRedisRedisR       Redi
   RedisRedisRedisRedisRedisRedisRedisRedis      R
  RedisRedisRedisRedisRedisRedisRedisRedisRedi  Red
  RedisRedisRedisRedisRedisRedisRedisRedisRedisRe R
  RedisRedisRedisRedisRedisRedisRedisRedisRedisRedi
  RedisRedisRedisRedisRedisRedisRedisRedisRedisRedi
   RedisRedisRedisRedisRedisRedisRedisRedisRedisRe
    RedisRedisRedisRedisRedisRedisRedisRedisRedis
      RedisRedisRedisRedisRedisRedisRedisRedisRe
        RedisRedisRedisRedisRedisRedisRedisRe
           RedisRedisRedisRedisRedisRedisR
              RedisRedisRedisRedisRedis
                RedisRedisRedisRedis
                   RedisRedisRed
                     RedisRedi
                       RedisR
                        Redi
                         Re

Contribution

Fork away. If you want to chat about a feature idea, or a question you can find me on the twitters @schneems. Put any major changes into feature branches. Make sure all tests stay green, and make sure your changes are covered.

licensed under MIT License Copyright (c) 2011 Schneems. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.