Module: RuleValidations
- Included in:
- PromotionalRule
- Defined in:
- lib/wunder/concerns/rule_validations.rb
Constant Summary collapse
- DISCOUNT_TYPES =
%w[percentage flat_rate].freeze
Instance Method Summary collapse
- #boolean?(attribute) ⇒ Boolean
- #check_discount_type(discount_type) ⇒ Object
- #either_should_be_present(name, attr1, attr2) ⇒ Object
- #should_be_a_boolean(name, attribute) ⇒ Object
- #should_be_a_number(name, attribute) ⇒ Object
- #should_be_more_than(name, attribute, number) ⇒ Object
- #should_be_present(name, attr) ⇒ Object
Instance Method Details
#boolean?(attribute) ⇒ Boolean
30 31 32 |
# File 'lib/wunder/concerns/rule_validations.rb', line 30 def boolean?(attribute) ["true", "false", true, false].include? attribute end |
#check_discount_type(discount_type) ⇒ Object
8 9 10 11 12 |
# File 'lib/wunder/concerns/rule_validations.rb', line 8 def check_discount_type(discount_type) discount_type_error = "Allowed values 'percentage' or 'flat_rate'" raise ArgumentError, discount_type_error unless DISCOUNT_TYPES.include?(discount_type) end |
#either_should_be_present(name, attr1, attr2) ⇒ Object
14 15 16 |
# File 'lib/wunder/concerns/rule_validations.rb', line 14 def either_should_be_present(name, attr1, attr2) raise "atleast fill out #{name}" if attr1.empty? && attr2.empty? end |
#should_be_a_boolean(name, attribute) ⇒ Object
26 27 28 |
# File 'lib/wunder/concerns/rule_validations.rb', line 26 def should_be_a_boolean(name, attribute) raise "#{name} should be a boolean" if boolean?(attribute) == false end |
#should_be_a_number(name, attribute) ⇒ Object
18 19 20 |
# File 'lib/wunder/concerns/rule_validations.rb', line 18 def should_be_a_number(name, attribute) raise "#{name} should be a number" if attribute.is_a?(Numeric) == false end |
#should_be_more_than(name, attribute, number) ⇒ Object
22 23 24 |
# File 'lib/wunder/concerns/rule_validations.rb', line 22 def should_be_more_than(name, attribute, number) raise "#{name} should be >= #{number}" if attribute < number end |
#should_be_present(name, attr) ⇒ Object
4 5 6 |
# File 'lib/wunder/concerns/rule_validations.rb', line 4 def should_be_present(name, attr) raise "#{name}.capitalize should be present" if attr == "" || attr.nil? end |