Module: PollBooth::ClassMethods

Defined in:
lib/pollbooth.rb

Instance Method Summary collapse

Instance Method Details

#cache(ttl, &block) ⇒ Object



45
46
47
48
# File 'lib/pollbooth.rb', line 45

def cache(ttl, &block)
  self.cache_block = block
  self.ttl = ttl
end

#lookup(value) ⇒ Object



39
40
41
42
43
# File 'lib/pollbooth.rb', line 39

def lookup(value)
 self.start unless self.poller.try(:started?)

 self.poller.lookup(value)
end

#start(cache_on = true) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pollbooth.rb', line 23

def start(cache_on=true)
  raise "you must provide cache block before starting" if self.cache_block.nil?

  self.class_variable_get(:@@pollbooth_mutex).synchronize do
    self.stop
    self.poller = Poller.new(self, cache_on)
  end

  PollBooth.pollers ||= []
  PollBooth.pollers << self.poller
end

#started?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/pollbooth.rb', line 50

def started?
  self.poller.try(:started?) || false
end

#stopObject



35
36
37
# File 'lib/pollbooth.rb', line 35

def stop
  self.poller.stop if self.poller
end