Class: CatalogItem::QuantityBoundsValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- CatalogItem::QuantityBoundsValidator
- Defined in:
- app/validators/catalog_item/quantity_bounds_validator.rb
Overview
app/validators/quantity_bounds_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate(record) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/validators/catalog_item/quantity_bounds_validator.rb', line 3 def validate(record) # Validate that quantity_discount_price_type is present if any quantity bounds are set validate_discount_price_type_presence(record) # Validate bounds and discount values (1..4).each do |i| lower_bound = record.send(:"quantity_#{i}_lower_bound") higher_bound = record.send(:"quantity_#{i + 1}_lower_bound") price_discount = record.send(:"quantity_#{i}_price_discount") next_price_discount = record.send(:"quantity_#{i + 1}_price_discount") validate_pair_presence(record, i, lower_bound, price_discount) validate_order(record, i, lower_bound, higher_bound, price_discount, next_price_discount) validate_price_discount_range(record, i, price_discount) end validate_pair_presence(record, 5, record.quantity_5_lower_bound, record.quantity_5_price_discount) validate_price_discount_range(record, 5, record.quantity_5_price_discount) end |