Module: Shattered::Timer::ClassMethods

Defined in:
lib/shattered_model/timer.rb

Instance Method Summary collapse

Instance Method Details

#timer(options = {}) ⇒ Object

Timers are controller events that occur after a specified period of time. The time values are seconds by default.

timer :in

If you want an event to occur once after a specified amount of time, use
   timer :in => 3.seconds, :action => :method_to_call

timer :every

If you want an event to occur once every specified amount of time, use
   timer :every => 3.seconds, :action => :method_to_call
If you want to be notified of every frame update, use
   timer :every => :frame, :action => :method_to_call

Inside the instance, you can still create timer events, using the timer object:

timer.in( 3.seconds ) { ... }
timer.every( 3.seconds ) { ... }


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/shattered_model/timer.rb', line 29

def timer(options = {})
  if options[:action].nil?
    throw Shattered::Error, 
      "Timer event must specify an :action => :method" 
  end
  if options[:in].nil? && options[:every].nil?
    throw Shattered::Error,
      "Timer event must specify a time.  (timer :in or timer :every)"
  end
  time = options[:in] || options[:every]
  action = options[:action]
  before_init_call(:create_timer, :in, time, action, options) unless options[:in].nil?
  before_init_call(:create_timer, :every, time, action, options) unless options[:every].nil?
end