Sha256: c9c0a4214ffebd28718d0405732cd97b1928a2a64690bd0eb1cc1b39ac6c0715

Contents?: true

Size: 675 Bytes

Versions: 2

Compression:

Stored size: 675 Bytes

Contents

require 'active_support/time'
require 'active_support/concern'

module Ripple
  # Adds automatic creation and update timestamps to a
  # {Ripple::Document} model.
  module Timestamps
    extend ActiveSupport::Concern

    module ClassMethods
      # Adds the :created_at and :updated_at timestamp properties to
      # the document.
      def timestamps!
        property :created_at, Time, :default => proc { Time.now }
        property :updated_at, Time
        before_save :touch
      end
    end

    module InstanceMethods
      # Sets the :updated_at attribute before saving the document.
      def touch
        self.updated_at = Time.now
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
seomoz-ripple-1.0.0.pre lib/ripple/timestamps.rb
ripple-1.0.0.beta lib/ripple/timestamps.rb