Sha256: cb6ff45c0e07f63dd3ea6c33547276be9e8bbbb143354a128515de8f4393dabf

Contents?: true

Size: 688 Bytes

Versions: 7

Compression:

Stored size: 688 Bytes

Contents

module HungryForm
  module 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)
        unless callable.respond_to? :call
          fail HungryFormError 'Validation must respond to call'
        end

        callable.call(element)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hungryform-0.0.11 lib/hungryform/validator.rb
hungryform-0.0.10 lib/hungryform/validator.rb
hungryform-0.0.9 lib/hungryform/validator.rb
hungryform-0.0.8 lib/hungryform/validator.rb
hungryform-0.0.7 lib/hungryform/validator.rb
hungryform-0.0.6 lib/hungryform/validator.rb
hungryform-0.0.4 lib/hungryform/validator.rb