class AutomationObject::BluePrint::HashAdapter::Validators::ValidateAllowedKeys

Validator that tests the composite hash for bad keys

Public Class Methods

new(args) click to toggle source

@param args [Hash] arguments for the validation class

# 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

Public Instance Methods

validate(composite_object) click to toggle source

Validates the composite object and throws errors on failure @param composite_object [Object] Composite object to be tested. @return [nil] no return on exceptions on failure

# 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|
    error_messages.push("Invalid Key: #{key}, at: #{composite_object.location}. Allowed keys: #{@allowed_keys}.") unless @allowed_keys.include?(key)
  end
end