Module: ActsAsPurchasable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/acts_as_purchasable.rb
Defined Under Namespace
Modules: Base, 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
63
64
65
66
67
68
69
70
71
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 63
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
73
74
75
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 73
def purchasable_name
to_s
end
|
#purchased? ⇒ Boolean
81
82
83
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 81
def purchased?
purchased_order_id.present?
end
|
#purchased_at ⇒ Object
85
86
87
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 85
def purchased_at
purchased_order.try(:purchased_at)
end
|
#purchased_by?(user) ⇒ Boolean
89
90
91
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 89
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.
93
94
95
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 93
def purchased_download_url false
end
|
#quantity_enabled? ⇒ Boolean
97
98
99
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 97
def quantity_enabled?
false
end
|
#quantity_remaining ⇒ Object
101
102
103
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 101
def quantity_remaining
quantity_max - quantity_purchased if quantity_enabled?
end
|
#sold_out? ⇒ Boolean
105
106
107
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 105
def sold_out?
quantity_enabled? ? (quantity_remaining <= 0) : false
end
|
#tax_exempt ⇒ Object
77
78
79
|
# File 'app/models/concerns/acts_as_purchasable.rb', line 77
def tax_exempt
self[:tax_exempt] || false
end
|