class Statlysis::Clock
Attributes
clock[RW]
Public Class Methods
new(feature, default_time = nil)
click to toggle source
feature is a string
# File lib/statlysis/clock.rb, line 9 def initialize feature, default_time = nil # init table & model cron.stat_table_name = [Statlysis.tablename_default_pre, 'clocks'].compact.join("_") unless Statlysis.sequel.table_exists?(cron.stat_table_name) Statlysis.sequel.create_table cron.stat_table_name, DefaultTableOpts.merge(:engine => "InnoDB") do primary_key :id String :feature DateTime :t index :feature, :unique => true end end h = Utils.setup_pattern_table_and_model cron.stat_table_name cron.stat_model = h[:model] # init default_time default_time ||= DateTime.now cron.clock = cron.stat_model.find_or_create(:feature => feature) cron.clock.update :t => default_time if cron.current.nil? cron end
Public Instance Methods
current()
click to toggle source
# File lib/statlysis/clock.rb, line 36 def current; cron.clock.t end
update(time = DateTime.now)
click to toggle source
# File lib/statlysis/clock.rb, line 30 def update time = DateTime.now time = DateTime.now if time == DateTime1970 return false if time && (time < cron.current) cron.clock.update :t => time end