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
39 40 41 42 43 44 45 |
# File 'app/models/spree/digital_link.rb', line 39 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
27 28 29 |
# File 'app/models/spree/digital_link.rb', line 27 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.
49 50 51 52 53 |
# File 'app/models/spree/digital_link.rb', line 49 def ActiveRecord::Base.connected_to(role: :writing) do && increment!(:access_counter, touch: true) end end |
#expired? ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'app/models/spree/digital_link.rb', line 31 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
55 56 57 58 59 |
# File 'app/models/spree/digital_link.rb', line 55 def reset! self.access_counter = 0 self.created_at = Time.current save! end |