Sha256: 8316c844d5b58c0602f85ac8abac6a29d42420ac54e07c6ab728170ac8c6c81c

Contents?: true

Size: 518 Bytes

Versions: 3

Compression:

Stored size: 518 Bytes

Contents

class HashValidator::Validator::SimpleValidator < HashValidator::Validator::Base
  attr_accessor :lambda


  def initialize(name, lambda)
    # lambda must accept one argument (the value)
    if lambda.arity != 1
      raise StandardError.new("lambda should take only one argument - passed lambda takes #{lambda.arity}")
    end

    super(name)
    self.lambda = lambda
  end

  def validate(key, value, _validations, errors)
    unless lambda.call(value)
      errors[key] = presence_error_message
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hash_validator-1.1.0 lib/hash_validator/validators/simple_validator.rb
hash_validator-1.0.0 lib/hash_validator/validators/simple_validator.rb
hash_validator-0.8.0 lib/hash_validator/validators/simple_validator.rb