module AutomationObject::BluePrint::HashAdapter::ValidationHelper

Validation helper for the composite structure, will allow Rails style validations on the composite

Attributes

errors[RW]

Public Class Methods

included(base) click to toggle source
# File lib/automation_object/blue_print/hash_adapter/helpers/validation_helper.rb, line 54
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

add_errors(errors) click to toggle source

Give errors a default empty Array @params [Array<String>] error messages @return [Array<String>] error messages

# File lib/automation_object/blue_print/hash_adapter/helpers/validation_helper.rb, line 32
def add_errors(errors)
  self.errors += errors
end
valid?() click to toggle source

@return [Boolean] composite valid?

# File lib/automation_object/blue_print/hash_adapter/helpers/validation_helper.rb, line 37
def valid?
  return true if self.class.skip_validations

  # ap self.class
  # ap self.class.name
  self.class.validations.collect do |validation|
    # ap validation.class.name
  end

  self.class.validations.collect do |validation|
    validation.validate(self)
    add_errors(validation.error_messages) unless validation.valid?
  end

  self.errors.empty?
end