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
72
73
74
75
76
77
78
79
80
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 72
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
82
83
84
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 82
def purchasable_name
to_s
end
|
#purchased? ⇒ Boolean
90
91
92
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 90
def purchased?
purchased_order_id.present?
end
|
#purchased_at ⇒ Object
94
95
96
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 94
def purchased_at
purchased_order.try(:purchased_at)
end
|
#purchased_by?(user) ⇒ Boolean
98
99
100
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 98
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.
102
103
104
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 102
def purchased_download_url false
end
|
#quantity_enabled? ⇒ Boolean
106
107
108
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 106
def quantity_enabled?
false
end
|
#quantity_remaining ⇒ Object
110
111
112
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 110
def quantity_remaining
quantity_max - quantity_purchased if quantity_enabled?
end
|
#sold_out? ⇒ Boolean
114
115
116
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 114
def sold_out?
quantity_enabled? ? (quantity_remaining <= 0) : false
end
|
#tax_exempt ⇒ Object
86
87
88
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 86
def tax_exempt
self[:tax_exempt] || false
end
|