Class: Etna::Clients::Magma::AttributeActionValidatorBase
Instance Attribute Summary collapse
#errors
Instance Method Summary
collapse
#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
Returns a new instance of AttributeActionValidatorBase.
271
272
273
274
275
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 271
def initialize(action, project_models)
super()
@action = action
@project_models = project_models
end
|
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
269
270
271
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 269
def action
@action
end
|
#project_models ⇒ Object
Returns the value of attribute project_models.
269
270
271
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 269
def project_models
@project_models
end
|
Instance Method Details
#action_to_attribute(action) ⇒ Object
277
278
279
280
281
282
283
284
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 277
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
298
299
300
301
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 298
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
303
304
305
306
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 303
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
290
291
292
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 290
def exists_in_magma_model?(magma_model_name, attribute_name)
!!project_models.model(magma_model_name).template.attributes.attribute(attribute_name)
end
|
#validate ⇒ Object
286
287
288
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 286
def validate
raise "Subclasses must implement this method."
end
|
#validate_model_exists(magma_model_name) ⇒ Object
294
295
296
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 294
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
|