Sha256: 71bdfb2cde77056778a679383475a3a4d89e9ecd0dda2010bb255d2ea510c2dd

Contents?: true

Size: 655 Bytes

Versions: 10

Compression:

Stored size: 655 Bytes

Contents

module Ohm
  # Provides created_at / updated_at timestamps.
  #
  # @example
  #
  #   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
  module Timestamping
    def self.included(base)
      base.attribute :created_at
      base.attribute :updated_at
    end

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

      super
    end

  protected
    def write
      self.updated_at ||= Time.now.utc

      super
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ohm-contrib-0.0.26 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.25 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.24 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.23 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.22 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.21 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.20 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.19 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.18 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.17 lib/ohm/contrib/timestamping.rb