Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions lib/ohm/timestamps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,35 @@ module Ohm
# post.updated_at.to_i == Time.now.utc.to_i
# # => true
module Timestamps
def self.included(model)
model.attribute :created_at, DataTypes::Type::Timestamp
model.attribute :updated_at, DataTypes::Type::Timestamp
module Created
def self.included(model)
model.attribute :created_at, DataTypes::Type::Timestamp
end

def save!
self.created_at = Time.now.utc.to_i if new?

super
end
end

def save!
self.created_at = Time.now.utc.to_i if new?
self.updated_at = Time.now.utc.to_i
module Updated
def self.included(model)
model.attribute :updated_at, DataTypes::Type::Timestamp
end

def save!
self.updated_at = Time.now.utc.to_i

super
super
end
end

def self.included(model)
model.class_eval do
include Created
include Updated
end
end
end
end