Class: AutomationObject::BluePrint::HashAdapter::Validators::ValidateInstanceOf
- Inherits:
-
Validate
- Object
- Validate
- AutomationObject::BluePrint::HashAdapter::Validators::ValidateInstanceOf
- Defined in:
- lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_instance_of.rb
Overview
Validator that tests that a element is defined when it is called elsewhere through a hook
Instance Attribute Summary
Attributes inherited from Validate
Instance Method Summary collapse
-
#initialize(args) ⇒ ValidateInstanceOf
constructor
A new instance of ValidateInstanceOf.
-
#validate(composite_object) ⇒ nil
Validates the composite object and adds errors on failure.
Methods inherited from Validate
Constructor Details
#initialize(args) ⇒ ValidateInstanceOf
Returns a new instance of ValidateInstanceOf
12 13 14 15 16 |
# File 'lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_instance_of.rb', line 12 def initialize(args) @key = args.fetch :key # Convert to array of instances for consistency @should_be_instances_of = args.fetch(:args).is_a?(Array) ? args.fetch(:args) : [args.fetch(:args)] end |
Instance Method Details
#validate(composite_object) ⇒ nil
Validates the composite object and adds errors on failure
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_instance_of.rb', line 21 def validate(composite_object) # Get the hash value from the composite object target_value = composite_object.hash[@key] # Skip empty or non-existent return unless target_value return if @should_be_instances_of.any? { |should_instance| target_value.is_a?(should_instance) } = "Invalid Type: #{target_value.class}, at: #{composite_object.location}[#{@key}]." += " Allowed Type(s): #{@should_be_instances_of}" .push() end |