Class: Etna::Clients::Magma::RenamesValidator

Inherits:
ValidatorBase show all
Defined in:
lib/etna/clients/magma/workflows/json_validators.rb

Instance Attribute Summary collapse

Attributes inherited from ValidatorBase

#errors

Instance Method Summary collapse

Methods inherited from ValidatorBase

#check_in_set, #check_key, #check_key_empty, #check_valid_name_with_numbers, #format_errors, #model_exists_in_project?, #name_regex_no_numbers, #name_regex_with_numbers, #nil_or_empty?, #valid?, #validate!

Constructor Details

#initialize(models = Models.new, renames = {}) ⇒ RenamesValidator

Returns a new instance of RenamesValidator.



84
85
86
87
88
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 84

def initialize(models = Models.new, renames = {})
  @models = models
  @renames = renames
  super()
end

Instance Attribute Details

#modelsObject (readonly)

Returns the value of attribute models.



83
84
85
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 83

def models
  @models
end

#renamesObject (readonly)

Returns the value of attribute renames.



83
84
85
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 83

def renames
  @renames
end

Instance Method Details

#validateObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 90

def validate
  renames.each do |model_name, attribute_renames|
    attribute_renames.each do |old_name, new_name|
      keys = @models.build_model(model_name).build_template.build_attributes.attribute_keys
      if keys.include?(new_name)
        @errors << "Model #{model_name} trying to rename #{old_name} to #{new_name}, but a different #{new_name} already exists."
      end

      if !keys.include?(old_name)
        @errors << "Model #{model_name} trying to rename #{old_name} to #{new_name}, but #{old_name} does not exist."
      end
    end
  end
end