Class: AutomationObject::BluePrint::HashAdapter::Validators::ValidatePresenceOf
- Inherits:
-
Validate
- Object
- Validate
- AutomationObject::BluePrint::HashAdapter::Validators::ValidatePresenceOf
- Defined in:
- lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_presence_of.rb
Overview
Validates tests the a key exists on a composite hash
Instance Attribute Summary
Attributes inherited from Validate
Instance Method Summary collapse
-
#initialize(args) ⇒ ValidatePresenceOf
constructor
A new instance of ValidatePresenceOf.
-
#validate(composite_object) ⇒ nil
Validates the composite object and throws errors on failure.
Methods inherited from Validate
Constructor Details
#initialize(args) ⇒ ValidatePresenceOf
Returns a new instance of ValidatePresenceOf
12 13 14 15 16 17 18 |
# File 'lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_presence_of.rb', line 12 def initialize(args) @key = args.fetch :key = args.fetch :args, {} = .is_a?(Hash) ? : {} @unless_presence_of = .fetch :unless_presence_of, nil end |
Instance Method Details
#validate(composite_object) ⇒ nil
Validates the composite object and throws errors on failure
23 24 25 26 27 28 29 30 31 32 33 |
# 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 .push("Required Key Missing: #{@key}, at: #{composite_object.location}.") end |