Class: HashValidator::Validator::SimpleValidator
- Defined in:
- lib/hash_validator/validators/simple_validator.rb
Instance Attribute Summary collapse
-
#lambda ⇒ Object
Returns the value of attribute lambda.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(name, lambda) ⇒ SimpleValidator
constructor
A new instance of SimpleValidator.
- #validate(key, value, _validations, errors) ⇒ Object
Methods inherited from Base
#presence_error_message, #should_validate?
Constructor Details
#initialize(name, lambda) ⇒ SimpleValidator
Returns a new instance of SimpleValidator.
5 6 7 8 9 10 11 12 13 |
# File 'lib/hash_validator/validators/simple_validator.rb', line 5 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 |
Instance Attribute Details
#lambda ⇒ Object
Returns the value of attribute lambda.
2 3 4 |
# File 'lib/hash_validator/validators/simple_validator.rb', line 2 def lambda @lambda end |
Instance Method Details
#validate(key, value, _validations, errors) ⇒ Object
15 16 17 18 19 |
# File 'lib/hash_validator/validators/simple_validator.rb', line 15 def validate(key, value, _validations, errors) unless lambda.call(value) errors[key] = end end |