Class: Spree::StoreCreditCategory
- Inherits:
-
Object
- Object
- Spree::StoreCreditCategory
- Defined in:
- app/models/spree/store_credit_category.rb
Constant Summary collapse
- GIFT_CARD_CATEGORY_NAME =
'Gift Card'.freeze
- DEFAULT_NON_EXPIRING_TYPES =
[GIFT_CARD_CATEGORY_NAME]
Class Method Summary collapse
Instance Method Summary collapse
- #can_be_deleted? ⇒ Boolean
- #non_expiring? ⇒ Boolean
- #non_expiring_category_types ⇒ Object
- #store_credit_category_used? ⇒ Boolean
- #validate_not_used ⇒ Object
Class Method Details
.default_reimbursement_category(_options = {}) ⇒ Object
36 37 38 |
# File 'app/models/spree/store_credit_category.rb', line 36 def default_reimbursement_category( = {}) Spree::StoreCreditCategory.first end |
Instance Method Details
#can_be_deleted? ⇒ Boolean
31 32 33 |
# File 'app/models/spree/store_credit_category.rb', line 31 def can_be_deleted? !store_credit_category_used? end |
#non_expiring? ⇒ Boolean
12 13 14 |
# File 'app/models/spree/store_credit_category.rb', line 12 def non_expiring? non_expiring_category_types.include? name end |
#non_expiring_category_types ⇒ Object
16 17 18 |
# File 'app/models/spree/store_credit_category.rb', line 16 def non_expiring_category_types DEFAULT_NON_EXPIRING_TYPES | Spree::Config[:non_expiring_credit_types] end |
#store_credit_category_used? ⇒ Boolean
20 21 22 |
# File 'app/models/spree/store_credit_category.rb', line 20 def store_credit_category_used? Spree::StoreCredit.exists?(category_id: id) end |
#validate_not_used ⇒ Object
24 25 26 27 28 29 |
# File 'app/models/spree/store_credit_category.rb', line 24 def validate_not_used if store_credit_category_used? errors.add(:base, :cannot_destroy_if_used_in_store_credit) throw(:abort) end end |