Module: Ohm::Timestamping

Defined in:
lib/ohm/contrib/timestamping.rb

Overview

Provides created_at / updated_at timestamps.

Examples:


class Post < Ohm::Model
  include Ohm::Timestamping
end

post = Post.create
post.created_at.to_s == Time.now.utc.to_s
# => true

post = Post[post.id]
post.save
post.updated_at.to_s == Time.now.utc.to_s
# => true

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



19
20
21
22
# File 'lib/ohm/contrib/timestamping.rb', line 19

def self.included(base)
  base.attribute :created_at
  base.attribute :updated_at
end

Instance Method Details

#createObject



24
25
26
27
28
# File 'lib/ohm/contrib/timestamping.rb', line 24

def create
  self.created_at ||= Time.now.utc

  super
end