I usually start blog-based introductions to gems and libraries that I write with a narrative. Lately, however, I’ve been getting busier keeping up with the work I need to do for clients and that I need to do for my startup. So I’ll leave the narrative to a minimum, a very short question.
You love the acts_as_follower gem, right? Sure, everyone does. Wouldn’t it be better if it was based in Redis? Sure, of course it would.
This weekend I found the great Amico gem, a low-level Ruby gem for Redis backed followers, and I decided to create Acts_as_Amico, a Rails injectable gem that uses that back-end ability, so now you can have a followers gem that is completely in Redis right in your Rails app.
The code has full-ish, but ever expanding, documentation on the Github page, but here’s a quick rundown
class User < ActiveRecord::Base acts_as_amico end usera = User.create userb = user.create usera.follow! userb => nil usera.following? userb => true
class Admin < ActiveRecord::Base acts_as_amico :amico_key => :name validates_uniqueness_of :name # -> do this or be sorry validates_presence_of :name # -> this too, you've been warned end usera = User.create puts usera.id => 18 admin = Admin.create :name => "frank" usera.follow! admin => nil admin.follow! usera => [1, 1] admin.followers => ["18"] usera.followers => ["frank"]
class RestObject < ActiveResource::Base self.site = "http://mettadore.com/junk" acts_as_amico :amico_key => :title end usera = User.create rest_object = RestObject.find(123) rest_object.title => "Bread and Circus" usera.follow! rest_object usera.following? rest_object => true usera.following => ["Bread and Circus"]