Sha256: 3aae867b3c620ef4aaf3901ae67ed74b5a372f42bd1e5fe2e847c40e8c5241ea
Contents?: true
Size: 874 Bytes
Versions: 6
Compression:
Stored size: 874 Bytes
Contents
module Sequel::Plugins::LuxBeforeSave module InstanceMethods def before_save # timestamps self[:created_at] = Time.now.utc if !self[:id] && respond_to?(:created_at) self[:updated_at] ||= Time.now.utc if respond_to?(:updated_at) # return error if user needed and not defined if !User.current && (respond_to?(:created_by) || respond_to?(:updated_by)) errors.add(:base, 'You have to be registered to save data') return end # add timestamps self[:created_by] = User.current.id if respond_to?(:created_by) && !id self[:updated_by] ||= User.current.id if respond_to?(:updated_by) # delete cache key if defined Lux.cache.delete(cache_key) super end def before_destroy Lux.cache.delete(cache_key) super end end end Sequel::Model.plugin :lux_before_save
Version data entries
6 entries across 6 versions & 1 rubygems