Sha256: f3b1082a5a680f4b993a5b7bd342ab2f19a1d7ea16742f12ba6dfef9c06fd7c2

Contents?: true

Size: 672 Bytes

Versions: 3

Compression:

Stored size: 672 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!(options={})
        property :created_at, Time, options.merge(:default => proc { Time.now })
        property :updated_at, Time, options.dup
        before_save :touch
      end
    end

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

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
wyngle-ripple-0.1.0 lib/ripple/timestamps.rb
better-ripple-1.0.0 lib/ripple/timestamps.rb
ripple-1.0.0.beta2 lib/ripple/timestamps.rb