Sha256: 2717ad9f36f08dae0c548c9eecbb3f6456e004f8101696a10a2b01ddcd4e04fc
Contents?: true
Size: 785 Bytes
Versions: 10
Compression:
Stored size: 785 Bytes
Contents
class SingleUseLink < ActiveRecord::Base validate :expiration_date_cannot_be_in_the_past validate :cannot_be_destroyed after_initialize :set_defaults def create_for_path path self.class.create :itemId => itemId, :path => path end def expired? DateTime.now > expires end def to_param downloadKey end protected def expiration_date_cannot_be_in_the_past if expired? errors.add(:expires, "can't be in the past") end end def cannot_be_destroyed if destroyed? errors[:base] << "Single Use Link has already been used" end end def set_defaults if new_record? self.expires ||= DateTime.now.advance(hours:24) self.downloadKey ||= (Digest::SHA2.new << rand(1000000000).to_s).to_s end end end
Version data entries
10 entries across 10 versions & 2 rubygems