Sha256: ca08e9a5ba7aef2a38b106750b4a5335c5b089a8a6a511d16830089ff0d82ef1
Contents?: true
Size: 857 Bytes
Versions: 20
Compression:
Stored size: 857 Bytes
Contents
class SingleUseLink < ActiveRecord::Base deprecated_attr_accessible :downloadKey, :path, :expires, :itemId 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
20 entries across 20 versions & 2 rubygems