Class: Compel::Validators::HashValidator
- Defined in:
- lib/compel/validators/hash_validator.rb
Instance Attribute Summary collapse
-
#keys_schemas ⇒ Object
readonly
Returns the value of attribute keys_schemas.
Attributes inherited from Base
#errors, #input, #output, #schema
Instance Method Summary collapse
-
#initialize(input, schema) ⇒ HashValidator
constructor
A new instance of HashValidator.
- #serialize ⇒ Object
- #serialize_errors ⇒ Object
- #validate ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(input, schema) ⇒ HashValidator
Returns a new instance of HashValidator.
11 12 13 14 15 16 |
# File 'lib/compel/validators/hash_validator.rb', line 11 def initialize(input, schema) super @errors = Errors.new @keys_schemas = schema.[:keys][:value] end |
Instance Attribute Details
#keys_schemas ⇒ Object (readonly)
Returns the value of attribute keys_schemas.
9 10 11 |
# File 'lib/compel/validators/hash_validator.rb', line 9 def keys_schemas @keys_schemas end |
Instance Method Details
#serialize ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/compel/validators/hash_validator.rb', line 32 def serialize coerced = output.is_a?(Hash) ? input.merge(output) : {} coerced.tap do |hash| if !errors.empty? hash[:errors] = serialize_errors end end end |
#serialize_errors ⇒ Object
42 43 44 |
# File 'lib/compel/validators/hash_validator.rb', line 42 def serialize_errors errors.to_hash end |
#validate ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/compel/validators/hash_validator.rb', line 18 def validate unless root_hash_valid? return self end keys_validator = \ HashKeysValidator.validate(input, keys_schemas) @errors = keys_validator.errors @output = keys_validator.output self end |