Skip to content

Commit 587f529

Browse files
author
Kevin Paulisse
committed
Create method to make code cleaner
1 parent db0aefa commit 587f529

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

lib/octocatalog-diff/catalog-diff/differ.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,8 @@ def catdiff
191191

192192
# Legacy options which are now filters
193193
@opts[:filters] ||= []
194-
if @opts[:suppress_absent_file_details] && !@opts[:filters].include?('AbsentFile')
195-
@opts[:filters] << 'AbsentFile'
196-
end
197-
@opts[:filters] << 'CompilationDir' unless @opts[:filters].include?('CompilationDir')
194+
add_element_to_array(@opts[:filters], 'CompilationDir')
195+
add_element_to_array(@opts[:filters], 'AbsentFile') if @opts[:suppress_absent_file_details]
198196

199197
# Apply any additional pluggable filters.
200198
filter_opts = {
@@ -209,6 +207,13 @@ def catdiff
209207
result
210208
end
211209

210+
# Add an element to an array if it doesn't already exist in that array
211+
# @param array_in [Array] Array to have element added (**mutated** by this method)
212+
# @param element [?] Element to add
213+
def add_element_to_array(array_in, element)
214+
array_in << element unless array_in.include?(element)
215+
end
216+
212217
# Filter the differences for any items that were ignored, by some combination of type, title, and
213218
# attribute. This modifies the array itself by selecting only items that do not meet the ignored
214219
# filter.

0 commit comments

Comments
 (0)