Class: AutomationObject::BluePrint::HashAdapter::Validators::ValidateAllowedKeys
- Inherits:
-
Validate
- Object
- Validate
- AutomationObject::BluePrint::HashAdapter::Validators::ValidateAllowedKeys
- Defined in:
- lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_allowed_keys.rb
Overview
Validator that tests the composite hash for bad keys
Instance Attribute Summary
Attributes inherited from Validate
Instance Method Summary collapse
-
#initialize(args) ⇒ ValidateAllowedKeys
constructor
A new instance of ValidateAllowedKeys.
-
#validate(composite_object) ⇒ nil
Validates the composite object and throws errors on failure.
Methods inherited from Validate
Constructor Details
#initialize(args) ⇒ ValidateAllowedKeys
Returns a new instance of ValidateAllowedKeys
12 13 14 |
# File 'lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_allowed_keys.rb', line 12 def initialize(args) @allowed_keys = args.fetch :allowed_keys end |
Instance Method Details
#validate(composite_object) ⇒ nil
Validates the composite object and throws errors on failure
19 20 21 22 23 24 25 26 |
# File 'lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_allowed_keys.rb', line 19 def validate(composite_object) # Get the hash from the composite object target_hash = composite_object.hash target_hash.each_key do |key| .push("Invalid Key: #{key}, at: #{composite_object.location}. Allowed keys: #{@allowed_keys}.") unless @allowed_keys.include?(key) end end |