Class: AutomationObject::BluePrint::HashAdapter::Validators::ValidateElementPresenceOf

Inherits:
Validate
  • Object
show all
Defined in:
lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_element_presence_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

#error_messages

Instance Method Summary collapse

Methods inherited from Validate

#valid?

Constructor Details

#initialize(args) ⇒ ValidateElementPresenceOf

Returns a new instance of ValidateElementPresenceOf

Parameters:

  • args (Hash)

    arguments for the validation class



12
13
14
# File 'lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_element_presence_of.rb', line 12

def initialize(args)
  @key = args.fetch :key
end

Instance Method Details

#validate(composite_object) ⇒ nil

Validates the composite object and throws errors on failure

Parameters:

  • composite_object (Object)

    Composite object to be tested.

Returns:

  • (nil)

    no return on exceptions on failure



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_element_presence_of.rb', line 19

def validate(composite_object)
  # Get the hash value from the composite object
  target_value = composite_object.hash[@key]

  return unless target_value

  target_values = target_value.is_a?(Array) ? target_value : [target_value]
  valid_elements = find_elements(composite_object)

  populate_errors(target_values, valid_elements, composite_object)
end