Sha256: 3dfd5dca6fe46596d0a94edfe50477416e747ca815fcb9549e1a9d3b7e75bd85
Contents?: true
Size: 663 Bytes
Versions: 1
Compression:
Stored size: 663 Bytes
Contents
class HungryForm class Validator class << self # Check if the element's value is not empty. # The rule argument can be a boolean or a callable object def required(element, rule) if rule.respond_to? :call rule.call(element) else "is required" if element.value.to_s.empty? && rule end end # Custom validation check # Use when you need to create a custom validation in the structure def validation(element, callable) raise HungryFormError "Validation must respond to call" unless callable.respond_to? :call callable.call(element) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hungryform-0.0.2 | lib/hungryform/validator.rb |