class Fatboy::Many
This class provides a way to pipeline many different views, adding efficiency. Usage:
m = fatboy.many m[image] m[comment] m[comment2] m[description] m.commit!
Public Class Methods
new(redis)
click to toggle source
Don’t initialize this yourself.
# File lib/fatboy/many.rb, line 16 def initialize(redis) @redis = redis @models = [] end
Public Instance Methods
[](o)
click to toggle source
Alias for view
# File lib/fatboy/many.rb, line 22 def [](o) view o end
commit!()
click to toggle source
# File lib/fatboy/many.rb, line 29 def commit! stores = Fatboy::Helpers.all_format(Time.now) @redis.pipelined do @models.each do |model| redis_view(model, stores) end end end
view(obj)
click to toggle source
# File lib/fatboy/many.rb, line 25 def view(obj) @models << obj end
Protected Instance Methods
inc_member(store, id)
click to toggle source
# File lib/fatboy/many.rb, line 48 def inc_member(store, id) @redis.zincrby(store, 1, id) end
redis_view(model, stores)
click to toggle source
Basically copy/pasted from the Fatboy
class. The second argument is so that we don’t need to calculate the time string multiple times.
# File lib/fatboy/many.rb, line 42 def redis_view(model, stores) stores.each do |store| inc_member(store, model.id) end end