Module: ActsAsPurchasable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/acts_as_purchasable.rb
Defined Under Namespace
Modules: ActiveRecord, ClassMethods
Instance Method Summary
collapse
Instance Method Details
#price ⇒ Object
59
60
61
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 59
def price
self[:price] || 0
end
|
#price=(value) ⇒ Object
If I have a column type of Integer, and I’m passed a non-Integer, convert it here
64
65
66
67
68
69
70
71
72
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 64
def price=(value)
if value.kind_of?(Integer)
super
elsif value.kind_of?(String) && !value.include?('.')
super
else
raise 'expected price to be an Integer representing the number of cents.'
end
end
|
#purchased? ⇒ Boolean
92
93
94
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 92
def purchased?
@is_purchased ||= purchased_order.present?
end
|
#purchased_at ⇒ Object
100
101
102
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 100
def purchased_at
purchased_order.try(:purchased_at)
end
|
#purchased_by?(user) ⇒ Boolean
96
97
98
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 96
def purchased_by?(user)
purchased_orders.any? { |order| order.user_id == user.id }
end
|
#purchased_download_url ⇒ Object
Override me if this is a digital purchase.
117
118
119
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 117
def purchased_download_url
false
end
|
#purchased_order ⇒ Object
88
89
90
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 88
def purchased_order
@purchased_order ||= purchased_orders.first
end
|
#quantity_enabled? ⇒ Boolean
104
105
106
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 104
def quantity_enabled?
self.respond_to?(:quantity_enabled) ? quantity_enabled == true : false
end
|
#quantity_remaining ⇒ Object
108
109
110
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 108
def quantity_remaining
(quantity_max - quantity_purchased) rescue 0
end
|
#seller ⇒ Object
82
83
84
85
86
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 82
def seller
if EffectiveOrders.stripe_connect_enabled
raise 'acts_as_purchasable object requires the seller be defined to return the User selling this item. This is only a requirement when using StripeConnect.'
end
end
|
#sold_out? ⇒ Boolean
112
113
114
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 112
def sold_out?
quantity_enabled? ? (quantity_remaining == 0) : false
end
|
#tax_exempt ⇒ Object
78
79
80
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 78
def tax_exempt
self[:tax_exempt] || false
end
|
#title ⇒ Object
74
75
76
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 74
def title
self[:title] || to_s
end
|