class AutomationObject::BluePrint::HashAdapter::Validators::ValidatePresenceOf
Validates tests the a key exists on a composite hash
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_presence_of.rb, line 12 def initialize(args) @key = args.fetch :key options = args.fetch :args, {} options = options.is_a?(Hash) ? options : {} @unless_presence_of = options.fetch :unless_presence_of, nil 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_presence_of.rb, line 23 def validate(composite_object) # Get the hash value from the composite object return if composite_object.hash.key?(@key) # Do unless_presence_of check if @unless_presence_of return if composite_object.hash.key?(@unless_presence_of) end error_messages.push("Required Key Missing: #{@key}, at: #{composite_object.location}.") end