Class: Wire::ValidationBase

Inherits:
Object
  • Object
show all
Defined in:
lib/wire/model/validation.rb

Overview

Validation Base class

Direct Known Subclasses

AppGroupValidation, NetworksValidation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ ValidationBase

initializes the Validation object on given project



39
40
41
42
# File 'lib/wire/model/validation.rb', line 39

def initialize(project)
  @project = project
  @errors = []
end

Instance Attribute Details

#errorsObject

errors Array of validation errors, see class ValidationError



36
37
38
# File 'lib/wire/model/validation.rb', line 36

def errors
  @errors
end

Instance Method Details

#mark(message, element_type, element_name) ⇒ Object

adds a validation error to the error list message Validation Error message element_type Model element type of this error, i.e. ‘Network’ element_name Model element name



48
49
50
# File 'lib/wire/model/validation.rb', line 48

def mark(message, element_type, element_name)
  @errors << ValidationError.new(message, element_type, element_name)
end

#objects_attached_to_zones?(type_as_string) ⇒ Boolean

ensures that objects of given type_as_string (i.e. networks) are attached to zones

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
64
# File 'lib/wire/model/validation.rb', line 54

def objects_attached_to_zones?(type_as_string)
  zones = @project.get_element('zones')
  @project.get_element(type_as_string).each do |name, data|
    zone = data[:zone]    # assume that this object contains ref to a zone
    if !zone
      mark("#{type_as_string} is not attached to a zone", type_as_string, name)
    else
      mark("#{type_as_string} has invalid zone", type_as_string, name) unless zones.key?(zone)
    end
  end
end