Sha256: 487f712e812c5f81c2dac0d62f3cbee5e6891818017b1d7e071b183d25676df0

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

module Spontaneous
  module DataMapper

    def self.timestamp
      ::Sequel.datetime_class.now
    end

    module ContentModel
      module Timestamps
        def before_create
          set_create_timestamp
          super
        end

        # I have disabled update timestamps because the logic is more complex
        # than this. Modification timestamps are controlled by the modification
        # logic, e.g. preventing parent pages from appearing as modified on the
        # addition of a new child page.
        #
        # def before_update
        #   # set_update_timestamp
        #   super
        # end

        def set_create_timestamp(time=nil)
          return unless self.respond_to?(:created_at)
          time ||= Spontaneous::DataMapper.timestamp
          self.send(:"created_at=", time) if send(:created_at).nil?
          # set_update_timestamp(time)
        end

        # def set_update_timestamp(time=nil)
        #   return unless self.respond_to?(:modified_at)
        #   self.send(:modified_at=, time || Spontaneous::DataMapper.timestamp)
        # end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta5 lib/spontaneous/data_mapper/content_model/timestamps.rb
spontaneous-0.2.0.beta4 lib/spontaneous/data_mapper/content_model/timestamps.rb
spontaneous-0.2.0.beta3 lib/spontaneous/data_mapper/content_model/timestamps.rb
spontaneous-0.2.0.beta2 lib/spontaneous/data_mapper/content_model/timestamps.rb
spontaneous-0.2.0.beta1 lib/spontaneous/data_mapper/content_model/timestamps.rb