Class: Etna::Clients::Magma::AddLinkActionValidator
Instance Attribute Summary
#action, #project_models
#errors
Instance Method Summary
collapse
#action_to_attribute, #check_already_exists_in_model, #check_does_not_exist_in_model, #exists_in_magma_model?, #initialize, #validate_model_exists
#check_in_set, #check_key, #check_key_empty, #check_valid_name_with_numbers, #format_errors, #initialize, #model_exists_in_project?, #name_regex_no_numbers, #name_regex_with_numbers, #nil_or_empty?, #valid?, #validate!
Instance Method Details
#dest ⇒ Object
334
335
336
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 334
def dest
action.links.last
end
|
#source ⇒ Object
330
331
332
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 330
def source
action.links.first
end
|
#validate ⇒ Object
338
339
340
341
342
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 338
def validate
validate_links
validate_both_models_exist
validate_link_data
end
|
#validate_both_models_exist ⇒ Object
355
356
357
358
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 355
def validate_both_models_exist
validate_model_exists(source[:model_name])
validate_model_exists(dest[:model_name])
end
|
#validate_link_data ⇒ Object
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 360
def validate_link_data
link_types = Set.new([source[:type], dest[:type]])
expected_link_types = Set.new([
Etna::Clients::Magma::AttributeType::LINK,
Etna::Clients::Magma::AttributeType::COLLECTION
])
if link_types != expected_link_types
@errors << "You must have one \"link\" and one \"collection\" type in the links."
else
check_already_exists_in_model(source[:model_name], source[:attribute_name])
check_already_exists_in_model(dest[:model_name], dest[:attribute_name])
@errors << "Links #{source} and #{dest} must point to each other." unless source[:model_name] == dest[:attribute_name] && source[:attribute_name] == dest[:model_name]
end
end
|
#validate_links ⇒ Object
344
345
346
347
348
349
350
351
352
353
|
# File 'lib/etna/clients/magma/workflows/json_validators.rb', line 344
def validate_links
check_key("action #{action}", action, :links)
@errors << "Must include two link entries, each with \"model_name\", \"attribute_name\", and \"type\"." unless action.links.length == 2
check_key("link #{source}", source, :model_name)
check_key("link #{source}", source, :attribute_name)
check_key("link #{source}", source, :type)
check_key("link #{dest}", dest, :model_name)
check_key("link #{dest}", dest, :attribute_name)
check_key("link #{dest}", dest, :type)
end
|