class ActiveStorage::VerifiedKeyWithExpiration

Public Class Methods

decode(encoded_key) click to toggle source
# File lib/active_storage/verified_key_with_expiration.rb, line 9
def decode(encoded_key)
  key, expires_at = verifier.verified(encoded_key)

  key if key && fresh?(expires_at)
end
encode(key, expires_in: nil) click to toggle source
# File lib/active_storage/verified_key_with_expiration.rb, line 5
def encode(key, expires_in: nil)
  verifier.generate([ key, expires_at(expires_in) ])
end

Private Class Methods

expires_at(expires_in) click to toggle source
# File lib/active_storage/verified_key_with_expiration.rb, line 16
def expires_at(expires_in)
  expires_in ? Time.now.utc.advance(seconds: expires_in) : nil
end
fresh?(expires_at) click to toggle source
# File lib/active_storage/verified_key_with_expiration.rb, line 20
def fresh?(expires_at)
  expires_at.nil? || Time.now.utc < expires_at
end