Class: IOTA::Utils::ObjectValidator
- Inherits:
-
Object
- Object
- IOTA::Utils::ObjectValidator
- Defined in:
- lib/iota/utils/object_validator.rb
Instance Method Summary collapse
-
#initialize(keysToValidate) ⇒ ObjectValidator
constructor
A new instance of ObjectValidator.
- #valid?(object) ⇒ Boolean
Constructor Details
#initialize(keysToValidate) ⇒ ObjectValidator
Returns a new instance of ObjectValidator.
4 5 6 7 |
# File 'lib/iota/utils/object_validator.rb', line 4 def initialize(keysToValidate) @validator = InputValidator.new @keysToValidate = keysToValidate end |
Instance Method Details
#valid?(object) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/iota/utils/object_validator.rb', line 9 def valid?(object) valid = true @keysToValidate.each do |keyToValidate| key = keyToValidate[:key] func = keyToValidate[:validator] args = keyToValidate[:args] # If input does not have keyIndex and address, return false if !object.respond_to?(key) valid = false break end # If input function does not return true, exit method_args = [object.send(key)] method_args << args if !args.nil? if !@validator.method(func).call(*method_args) valid = false break end end valid end |