Class: Spree::DigitalLink
- Inherits:
-
Object
- Object
- Spree::DigitalLink
- Includes:
- Security::DigitalLinks
- 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
37 38 39 40 41 42 43 |
# File 'app/models/spree/digital_link.rb', line 37 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
25 26 27 |
# File 'app/models/spree/digital_link.rb', line 25 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.
47 48 49 50 51 |
# File 'app/models/spree/digital_link.rb', line 47 def ActiveRecord::Base.connected_to(role: :writing) do && increment!(:access_counter, touch: true) end end |
#expired? ⇒ Boolean
29 30 31 32 33 34 35 |
# File 'app/models/spree/digital_link.rb', line 29 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
53 54 55 56 57 |
# File 'app/models/spree/digital_link.rb', line 53 def reset! self.access_counter = 0 self.created_at = Time.current save! end |