Module: HungryForm::Validator
- Defined in:
- lib/hungryform/validator.rb
Class Method Summary collapse
-
.required(element, rule) ⇒ Object
Check if the element’s value is not empty.
-
.validation(element, callable) ⇒ Object
Custom validation check Use when you need to create a custom validation in the structure.
Class Method Details
.required(element, rule) ⇒ Object
Check if the element’s value is not empty. The rule argument can be a boolean or a callable object
6 7 8 9 10 11 12 |
# File 'lib/hungryform/validator.rb', line 6 def required(element, rule) if rule.respond_to? :call rule.call(element) else 'is required' if element.value.to_s.empty? && rule end end |
.validation(element, callable) ⇒ Object
Custom validation check Use when you need to create a custom validation in the structure
16 17 18 19 20 21 22 |
# File 'lib/hungryform/validator.rb', line 16 def validation(element, callable) unless callable.respond_to? :call fail HungryFormError 'Validation must respond to call' end callable.call(element) end |