class Wire::ValidationBase

Validation Base class

Attributes

errors[RW]

errors Array of validation errors, see class ValidationError

Public Class Methods

new(project) click to toggle source

initializes the Validation object on given project

# File lib/wire/model/validation.rb, line 39
def initialize(project)
  @project = project
  @errors = []
end

Public Instance Methods

mark(message, element_type, element_name) click to toggle source

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

# 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) click to toggle source

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

# 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