Sha256: ef6d957fe210f0dc7f35fd14a9c96fdbc5399f0d8a222e65bcc50e201bfc2a81

Contents?: true

Size: 517 Bytes

Versions: 13

Compression:

Stored size: 517 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

13 entries across 13 versions & 1 rubygems

Version Path
hash_validator-0.7.1 lib/hash_validator/validators/simple_validator.rb
hash_validator-0.7.0 lib/hash_validator/validators/simple_validator.rb
hash_validator-0.6.0 lib/hash_validator/validators/simple_validator.rb
hash_validator-0.5.0 lib/hash_validator/validators/simple_validator.rb
hash_validator-0.4.0 lib/hash_validator/validators/simple_validator.rb
hash_validator-0.3.0 lib/hash_validator/validators/simple_validator.rb
hash_validator-0.2.7 lib/hash_validator/validators/simple_validator.rb
hash_validator-0.2.6 lib/hash_validator/validators/simple_validator.rb
hash_validator-0.2.5 lib/hash_validator/validators/simple_validator.rb
hash_validator-0.2.4 lib/hash_validator/validators/simple_validator.rb
hash_validator-0.2.3 lib/hash_validator/validators/simple_validator.rb
hash_validator-0.2.2 lib/hash_validator/validators/simple_validator.rb
hash_validator-0.2.1 lib/hash_validator/validators/simple_validator.rb