16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/jets/resource/standardizer.rb', line 16
def standarize(definition)
first, second, third, _ = definition
if definition.size == 1 && first.is_a?(Hash) first elsif definition.size == 2 && second.is_a?(Hash) logical_id, attributes = first, second
attributes.delete(:properties) if attributes[:properties].nil? || attributes[:properties].empty?
{ logical_id => attributes }
elsif definition.size == 2 && second.is_a?(String) logical_id, type = first, second
{ logical_id => {
type: type
}}
elsif definition.size == 3 && (second.is_a?(String) || second.is_a?(NilClass)) logical_id, type, properties = first, second, third
template = { logical_id => {
type: type
}}
attributes = template.values.first
attributes[:properties] = properties unless properties.empty?
template
else raise "Invalid form provided. definition #{definition.inspect}"
end
end
|