module Familia::Stamps
class Example
include Familia field :name include Familia::Stamps
end
Public Class Methods
included(obj)
click to toggle source
# File lib/familia/helpers.rb, line 11 def self.included(obj) obj.module_eval do field :created => Integer field :updated => Integer def init_stamps now = Time.now.utc.to_i @created ||= now @updated ||= now end def created @created ||= Time.now.utc.to_i end def updated @updated ||= Time.now.utc.to_i end def created_age Time.now.utc.to_i-created end def updated_age Time.now.utc.to_i-updated end def update_time @updated = Time.now.utc.to_i end def update_time! update_time save if respond_to? :save @updated end end end
Public Instance Methods
created()
click to toggle source
# File lib/familia/helpers.rb, line 20 def created @created ||= Time.now.utc.to_i end
created_age()
click to toggle source
# File lib/familia/helpers.rb, line 26 def created_age Time.now.utc.to_i-created end
init_stamps()
click to toggle source
# File lib/familia/helpers.rb, line 15 def init_stamps now = Time.now.utc.to_i @created ||= now @updated ||= now end
update_time()
click to toggle source
# File lib/familia/helpers.rb, line 32 def update_time @updated = Time.now.utc.to_i end
update_time!()
click to toggle source
# File lib/familia/helpers.rb, line 35 def update_time! update_time save if respond_to? :save @updated end
updated()
click to toggle source
# File lib/familia/helpers.rb, line 23 def updated @updated ||= Time.now.utc.to_i end
updated_age()
click to toggle source
# File lib/familia/helpers.rb, line 29 def updated_age Time.now.utc.to_i-updated end