Class: Decidim::ShareToken
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::ShareToken
- 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
13 14 15 16 |
# File 'decidim-core/app/models/decidim/share_token.rb', line 13 def self.use!(token_for:, token:) record = find_by!(token_for:, token:) record.use! end |
Instance Method Details
#expired? ⇒ Boolean
24 25 26 |
# File 'decidim-core/app/models/decidim/share_token.rb', line 24 def expired? expires_at.past? end |
#url ⇒ Object
28 29 30 |
# File 'decidim-core/app/models/decidim/share_token.rb', line 28 def url token_for.shareable_url(self) end |
#use! ⇒ Object
18 19 20 21 22 |
# File 'decidim-core/app/models/decidim/share_token.rb', line 18 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 |