Class: Spree::DigitalLink
- Inherits:
-
Object
- Object
- Spree::DigitalLink
- Includes:
- Security::DigitalLinks, Webhooks::HasWebhooks
- Defined in:
- app/models/spree/digital_link.rb
Instance Method Summary collapse
- #access_limit_exceeded? ⇒ Boolean
- #authorizable? ⇒ Boolean
-
#authorize! ⇒ Object
This method should be called when a download is initiated.
- #expired? ⇒ Boolean
- #reset! ⇒ Object
Instance Method Details
#access_limit_exceeded? ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'app/models/spree/digital_link.rb', line 38 def access_limit_exceeded? if line_item.order.store.preferred_limit_digital_download_count access_counter >= line_item.order.store. else false end end |
#authorizable? ⇒ Boolean
26 27 28 |
# File 'app/models/spree/digital_link.rb', line 26 def !(expired? || access_limit_exceeded?) end |
#authorize! ⇒ Object
This method should be called when a download is initiated. It returns true or false depending on whether the authorization is granted.
48 49 50 51 52 |
# File 'app/models/spree/digital_link.rb', line 48 def ActiveRecord::Base.connected_to(role: :writing) do && increment!(:access_counter, touch: true) end end |
#expired? ⇒ Boolean
30 31 32 33 34 35 36 |
# File 'app/models/spree/digital_link.rb', line 30 def expired? if line_item.order.store.preferred_limit_digital_download_days created_at <= line_item.order.store..day.ago else false end end |
#reset! ⇒ Object
54 55 56 57 58 |
# File 'app/models/spree/digital_link.rb', line 54 def reset! self.access_counter = 0 self.created_at = Time.current save! end |