Sha256: 9917eb43625262ca30d77c9c78fae926de38e8a157faaf5d74b35c34118c8925
Contents?: true
Size: 705 Bytes
Versions: 6
Compression:
Stored size: 705 Bytes
Contents
require_relative "datatypes" module Ohm # Provides created_at / updated_at timestamps. # # @example # # class Post < Ohm::Model # include Ohm::Timestamps # end # # post = Post.create # post.created_at.to_i == Time.now.utc.to_i # # => true # # post = Post[post.id] # post.save # post.updated_at.to_i == Time.now.utc.to_i # # => true module Timestamps def self.included(model) model.attribute :created_at, DataTypes::Type::Timestamp model.attribute :updated_at, DataTypes::Type::Timestamp end def save self.created_at = Time.now.utc.to_i if new? self.updated_at = Time.now.utc.to_i super end end end
Version data entries
6 entries across 6 versions & 1 rubygems