Class: Fatboy::Many

Inherits:
Object
  • Object
show all
Defined in:
lib/fatboy/many.rb

Overview

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!

Instance Method Summary collapse

Constructor Details

#initialize(redis) ⇒ Many

Don't initialize this yourself.


16
17
18
19
# File 'lib/fatboy/many.rb', line 16

def initialize(redis)
  @redis = redis
  @models = []
end

Instance Method Details

#[](o) ⇒ Object

Alias for view


22
23
24
# File 'lib/fatboy/many.rb', line 22

def [](o)
  view o
end

#commit!Object


29
30
31
32
33
34
35
36
# 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) ⇒ Object


25
26
27
# File 'lib/fatboy/many.rb', line 25

def view(obj)
  @models << obj
end