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=(value) ⇒ Object
If I have a column type of Integer, and I’m passed a non-Integer, convert it here
70
71
72
73
74
75
76
77
78
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 70
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
|
#purchasable_name ⇒ Object
80
81
82
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 80
def purchasable_name
to_s
end
|
#purchased? ⇒ Boolean
88
89
90
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 88
def purchased?
purchased_order_id.present?
end
|
#purchased_at ⇒ Object
92
93
94
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 92
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.
100
101
102
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 100
def purchased_download_url false
end
|
#quantity_enabled? ⇒ Boolean
104
105
106
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 104
def quantity_enabled?
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 if quantity_enabled?
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
84
85
86
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 84
def tax_exempt
self[:tax_exempt] || false
end
|