Skip to content

Commit

Permalink
Rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
rileykarson committed Aug 28, 2019
1 parent 01ca0da commit 4e4e880
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions provider/terraform_kcc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ def guess_metadata_mapping_name(object)
# remove {{project}}, {{region}} if present, KCC handles them specially
final_import_parts -= ['{{project}}', '{{region}}']

if final_import_parts.length == 1
final_import_parts.first.gsub('{{', '').gsub('}}', '')
else
nil
end
final_import_parts.first.gsub('{{', '').gsub('}}', '') if final_import_parts.length == 1
end

def format_id_template(id_template, object)
Expand All @@ -117,10 +113,18 @@ def format_id_template(id_template, object)
id_template_formatted = id_template_parts.join('/')

# transform refs from {{bucket}} to {{bucketRef.name}} form
prop_names = id_template.scan(/{{[[:word:]]+}}/).map{ |p| p.gsub('{{', '').gsub('}}', '') }
prop_names = id_template.scan(/{{[[:word:]]+}}/).map { |p| p.gsub('{{', '').gsub('}}', '') }
# probably won't catch overriden names
object.all_properties.reject { |p| p.name == 'zone' }.select { |p| p.is_a?(Api::Type::ResourceRef) && (prop_names.include?(p.name) || prop_names.include?(p.name.camelize(:lower))) }.each do |prop|
id_template_formatted = id_template_formatted.gsub("{{#{prop.name}}}", "{{#{prop.name}Ref.name}}").gsub("{{#{prop.name.camelize(:lower)}}}", "{{#{prop.name}Ref.name}}")
object.all_properties
.reject { |p| p.name == 'zone' } # exclude special fields
.select { |p| p.is_a?(Api::Type::ResourceRef) } # select resource refs
.select { |p| prop_names.include?(p.name.camelize(:lower)) } # canonical name
.each do |prop|
id_template_formatted = id_template_formatted
.gsub(
"{{#{prop.name.camelize(:lower)}}}",
"{{#{prop.name}Ref.name}}"
)
end
id_template_formatted
end
Expand Down

0 comments on commit 4e4e880

Please sign in to comment.