Skip to content

Commit

Permalink
Make overrides directory work with examples and enums (GoogleCloudPla…
Browse files Browse the repository at this point in the history
  • Loading branch information
c2thorn authored and ericayyliu committed Jul 26, 2023
1 parent cb72bba commit e3e8cc9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mmv1/api/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,24 @@ def validate
check :values, type: ::Array, item_type: [Symbol, ::String, ::Integer], required: true
check :skip_docs_values, type: :boolean
end

def merge(other)
result = self.class.new
instance_variables.each do |v|
result.instance_variable_set(v, instance_variable_get(v))
end

other.instance_variables.each do |v|
if other.instance_variable_get(v).instance_of?(Array)
result.instance_variable_set(v, deep_merge(result.instance_variable_get(v),
other.instance_variable_get(v)))
else
result.instance_variable_set(v, other.instance_variable_get(v))
end
end

result
end
end

# Represents a 'selfLink' property, which returns the URI of the resource.
Expand Down
5 changes: 5 additions & 0 deletions mmv1/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@
else
File.read(override_path)
end
unless override_dir.nil?
# Replace overrides directory if we are running with a provider override
# This allows providers to reference files in their override path
res_yaml = res_yaml.gsub('{{override_path}}', override_dir)
end
resource = Api::Compiler.new(res_yaml).run
resource.validate
resources.push(resource)
Expand Down
18 changes: 18 additions & 0 deletions mmv1/provider/terraform/examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,24 @@ def validate
check :skip_vcr, type: TrueClass
check :pull_external, type: :boolean, default: false
end

def merge(other)
result = self.class.new
instance_variables.each do |v|
result.instance_variable_set(v, instance_variable_get(v))
end

other.instance_variables.each do |v|
if other.instance_variable_get(v).instance_of?(Array)
result.instance_variable_set(v, deep_merge(result.instance_variable_get(v),
other.instance_variable_get(v)))
else
result.instance_variable_set(v, other.instance_variable_get(v))
end
end

result
end
end
end
end

0 comments on commit e3e8cc9

Please sign in to comment.