Module: FatZebra::Validation
- Included in:
- FatZebraObject
- Defined in:
- lib/fat_zebra/validation.rb
Instance Method Summary collapse
- #errors ⇒ Object
- #valid!(params, action = nil) ⇒ Object
- #valid?(params, action = nil) ⇒ Boolean
- #validates(name, options = {}) ⇒ Object
Instance Method Details
#errors ⇒ Object
28 29 30 |
# File 'lib/fat_zebra/validation.rb', line 28 def errors @errors ||= [] end |
#valid!(params, action = nil) ⇒ Object
24 25 26 |
# File 'lib/fat_zebra/validation.rb', line 24 def valid!(params, action = nil) raise RequestValidationError, "The following errors prevent the transaction from being submitted: #{errors.join(', ')}" unless valid?(params, action) end |
#valid?(params, action = nil) ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fat_zebra/validation.rb', line 10 def valid?(params, action = nil) @errors = [] validations.each do |(field, )| next unless [:on] == action Util.hash_except(, :on).each do |(validation_attribute, )| send("validate_#{validation_attribute}", field, , params) end end errors.empty? end |
#validates(name, options = {}) ⇒ Object
6 7 8 |
# File 'lib/fat_zebra/validation.rb', line 6 def validates(name, = {}) validations[name] = end |