Skip to content

Commit 28c4c5b

Browse files
committed
Add regexp overrides to ENC too
1 parent 87123fb commit 28c4c5b

File tree

2 files changed

+18
-2
lines changed
  • lib/octocatalog-diff/catalog-util
  • spec/octocatalog-diff/tests/catalog-util

2 files changed

+18
-2
lines changed

lib/octocatalog-diff/catalog-util/enc.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ def override_enc_parameters(logger)
6565
return unless @options[:enc_override].is_a?(Array) && @options[:enc_override].any?
6666
content_structure = YAML.load(content)
6767
@options[:enc_override].each do |x|
68-
merge_enc_param(content_structure, x.key, x.value)
69-
logger.debug "ENC override: #{x.key} #{x.value.nil? ? 'DELETED' : '= ' + x.value.inspect}"
68+
keys = x.key.is_a?(Regexp) ? content_structure.keys.select { |y| x.key.match(y) } : [x.key]
69+
keys.each do |key|
70+
merge_enc_param(content_structure, key, x.value)
71+
logger.debug "ENC override: #{key} #{x.value.nil? ? 'DELETED' : '= ' + x.value.inspect}"
72+
end
7073
end
7174
@content = content_structure.to_yaml
7275
end

spec/octocatalog-diff/tests/catalog-util/enc_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,19 @@
154154
logs = @logger_str.string.split(/\n/).compact.map { |x| OctocatalogDiff::Spec.strip_log_message(x) }
155155
expect(logs).to include('DEBUG - ENC override: foo = "bar"')
156156
end
157+
158+
it 'should handle regexp overrides' do
159+
options = {
160+
enc_override: [OctocatalogDiff::API::V1::Override.create_from_input('/o+/=(string)bar')]
161+
}
162+
subject = described_class.allocate
163+
subject.instance_variable_set('@options', options)
164+
subject.instance_variable_set('@content', "---\nfoo: baz\nfizz: buzz\n")
165+
subject.send(:override_enc_parameters, @logger)
166+
expect(subject.instance_variable_get('@content')).to eq("---\nfoo: bar\nfizz: buzz\n")
167+
logs = @logger_str.string.split(/\n/).compact.map { |x| OctocatalogDiff::Spec.strip_log_message(x) }
168+
expect(logs).to include('DEBUG - ENC override: foo = "bar"')
169+
end
157170
end
158171

159172
describe '#merge_enc_param' do

0 commit comments

Comments
 (0)