Class: Wire::ValidateCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Wire::ValidateCommand
- Defined in:
- lib/wire/commands/validate_command.rb
Overview
Validate Command reads yaml, parses model elements and runs a number of consistency checks
Instance Attribute Summary collapse
-
#errors ⇒ Object
array of
errors. -
#validations ⇒ Object
array of validations.
Attributes inherited from BaseCommand
Instance Method Summary collapse
-
#initialize ⇒ ValidateCommand
constructor
initializes an empty error list.
-
#run_on_project ⇒ Object
runs validation on given project returns => list of
errors. -
#run_validation(project, validation_class) ⇒ Object
run a validation of given
validation_classagainst the model.
Methods inherited from BaseCommand
#check_user, #default_handle_resource, #dump_state, #ensure_hostip_netmask, #objects_in_zone, #outputs, #run, #state
Constructor Details
#initialize ⇒ ValidateCommand
initializes an empty error list
19 20 21 22 |
# File 'lib/wire/commands/validate_command.rb', line 19 def initialize @errors = [] @validations = [NetworksValidation, AppGroupValidation] end |
Instance Attribute Details
#errors ⇒ Object
array of errors
13 14 15 |
# File 'lib/wire/commands/validate_command.rb', line 13 def errors @errors end |
#validations ⇒ Object
array of validations
16 17 18 |
# File 'lib/wire/commands/validate_command.rb', line 16 def validations @validations end |
Instance Method Details
#run_on_project ⇒ Object
runs validation on given project returns
> list of errors
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/wire/commands/validate_command.rb', line 27 def run_on_project @errors = [] # run validations against it # TODO: Move validation classes to class level definition @validations.each do |val_clazz| (@errors << run_validation(@project, val_clazz)).flatten! end if @errors.size == 0 outputs 'VALIDATE', 'OK, model is consistent.', :ok else outputs 'VALIDATE', 'ERROR, detected inconsistencies:', :error @errors.each do |val_error| outputs 'VALIDATE', val_error.to_s, :error end end @errors end |
#run_validation(project, validation_class) ⇒ Object
run a validation of given validation_class against the model
params:
project-
project model object, to validate
validation_class-
class object of validation, i.e. NetworksValidation
returns: list of errors from validation object
57 58 59 60 61 62 |
# File 'lib/wire/commands/validate_command.rb', line 57 def run_validation(project, validation_class) $log.debug "Running validation class #{validation_class}" val_object = validation_class.new(project) val_object.run_validations val_object.errors end |