Sha256: 6ff8e7176c9680e217d44225ff13e47cf3e1594877669cd3716edceeed302ad7

Contents?: true

Size: 665 Bytes

Versions: 13

Compression:

Stored size: 665 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.to_s

      super
    end

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

      super
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ohm-contrib-0.1.2 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.1.1 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.1.0 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.42 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.41 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.40 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.39 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.38 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.37 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.36 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.35 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.34 lib/ohm/contrib/timestamping.rb
ohm-contrib-0.0.33 lib/ohm/contrib/timestamping.rb