Class: SingleUseLink

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/single_use_link.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_download_keyObject



11
12
13
# File 'app/models/single_use_link.rb', line 11

def self.generate_download_key
  (Digest::SHA2.new << rand(1_000_000_000).to_s).to_s
end

Instance Method Details

#create_for_path(path) ⇒ Object



15
16
17
# File 'app/models/single_use_link.rb', line 15

def create_for_path(path)
  self.class.create(item_id: item_id, path: path)
end

#expired?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/models/single_use_link.rb', line 19

def expired?
  DateTime.current > expires
end

#to_paramObject



23
24
25
# File 'app/models/single_use_link.rb', line 23

def to_param
  download_key
end