module Ork::Timestamps

Constants

VERSION

Public Class Methods

included(klass) click to toggle source
# File lib/ork/timestamps.rb, line 5
def self.included(klass)
  raise Ork::NotOrkObject unless klass.include? Ork::Document

  klass.class_eval do |base|
    attribute :created_at, accessors: :reader
    attribute :updated_at, accessors: :reader

    def created_at=(a)
      @attributes[:created_at] = Time.parse a.to_s
    end

    def updated_at=(a)
      @attributes[:updated_at] = Time.parse a.to_s
    end

    def save_with_timestamps
      self.created_at = Time.now if self.new?
      self.updated_at = Time.now

      save_without_timestamps
    end

    alias :save_without_timestamps :save
    alias :save :save_with_timestamps
  end
end

Public Instance Methods

created_at=(a) click to toggle source
# File lib/ork/timestamps.rb, line 12
def created_at=(a)
  @attributes[:created_at] = Time.parse a.to_s
end
save_with_timestamps() click to toggle source
# File lib/ork/timestamps.rb, line 20
def save_with_timestamps
  self.created_at = Time.now if self.new?
  self.updated_at = Time.now

  save_without_timestamps
end
updated_at=(a) click to toggle source
# File lib/ork/timestamps.rb, line 16
def updated_at=(a)
  @attributes[:updated_at] = Time.parse a.to_s
end