Class: Decidim::ShareToken

Inherits:
ApplicationRecord show all
Defined in:
decidim-core/app/models/decidim/share_token.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.use!(token_for:, token:) ⇒ Object


15
16
17
18
# File 'decidim-core/app/models/decidim/share_token.rb', line 15

def self.use!(token_for:, token:)
  record = find_by!(token_for: token_for, token: token)
  record.use!
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'decidim-core/app/models/decidim/share_token.rb', line 26

def expired?
  expires_at.past?
end

#urlObject


30
31
32
# File 'decidim-core/app/models/decidim/share_token.rb', line 30

def url
  token_for.shareable_url(self)
end

#use!Object


20
21
22
23
24
# File 'decidim-core/app/models/decidim/share_token.rb', line 20

def use!
  return raise StandardError, "Share token '#{token}' for '#{token_for_type}' with id = #{token_for_id} has expired." if expired?

  update!(times_used: times_used + 1, last_used_at: Time.zone.now)
end