Class: Etna::Clients::Magma::AttributeActionValidatorBase
Instance Attribute Summary collapse
#errors
Instance Method Summary
collapse
#check_in_set, #check_key, #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
Returns a new instance of AttributeActionValidatorBase.
266
267
268
269
270
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 266
def initialize(action, project_models)
super()
@action = action
@project_models = project_models
end
|
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
264
265
266
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 264
def action
@action
end
|
#project_models ⇒ Object
Returns the value of attribute project_models.
264
265
266
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 264
def project_models
@project_models
end
|
Instance Method Details
#action_to_attribute(action) ⇒ Object
272
273
274
275
276
277
278
279
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 272
def action_to_attribute(action)
action_json = JSON.parse(action.to_json)
action_json['attribute_type'] = action_json.delete('type')
action_json['desc'] = action_json.delete('description')
Etna::Clients::Magma::Attribute.new(action_json)
end
|
#check_already_exists_in_model(magma_model_name, attribute_name) ⇒ Object
293
294
295
296
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 293
def check_already_exists_in_model(magma_model_name, attribute_name)
return unless model_exists_in_project?(project_models, magma_model_name)
@errors << "Attribute \"#{attribute_name}\" already exists in model #{magma_model_name}." if exists_in_magma_model?(magma_model_name, attribute_name)
end
|
#check_does_not_exist_in_model(magma_model_name, attribute_name) ⇒ Object
298
299
300
301
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 298
def check_does_not_exist_in_model(magma_model_name, attribute_name)
return unless model_exists_in_project?(project_models, magma_model_name)
@errors << "Attribute \"#{attribute_name}\" does not exist in model #{magma_model_name}." unless exists_in_magma_model?(magma_model_name, attribute_name)
end
|
#exists_in_magma_model?(magma_model_name, attribute_name) ⇒ Boolean
285
286
287
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 285
def exists_in_magma_model?(magma_model_name, attribute_name)
!!project_models.model(magma_model_name).template.attributes.attribute(attribute_name)
end
|
#validate ⇒ Object
281
282
283
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 281
def validate
raise "Subclasses must implement this method."
end
|
#validate_model_exists(magma_model_name) ⇒ Object
289
290
291
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 289
def validate_model_exists(magma_model_name)
@errors << "Model \"#{magma_model_name}\" does not exist in project." unless model_exists_in_project?(project_models, magma_model_name)
end
|