File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
lib/facter/custom_facts/util Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -177,12 +177,20 @@ def sort_by_weight(resolutions)
177177 # - descending by weight
178178 # - multiple facts have the same weight but different types, the :external fact take precedence
179179 # - multiple facts with the same weight and type, the order is preserved.
180- # note: sort_by is slower than .sort
180+ # note: sort_by with index is slower than .sort
181181 # we cannot use .sort because it is not stable: https://bugs.ruby-lang.org/issues/1089
182-
183182 # solution from: https://bugs.ruby-lang.org/issues/1089#note-10
183+
184+ # rubocop:disable Style/NestedTernaryOperator
184185 idx = 0
185- resolutions . sort_by { |x | [ -x . weight , ( x . fact_type == :external ? 0 : 1 ) , idx += 1 ] }
186+ resolutions . sort_by do |x |
187+ [
188+ -x . weight ,
189+ x . respond_to? ( :fact_type ) ? x . fact_type == :external ? 0 : 1 : 1 ,
190+ idx += 1
191+ ]
192+ end
193+ # rubocop:enable Style/NestedTernaryOperator
186194 end
187195
188196 def find_first_real_value ( resolutions )
You can’t perform that action at this time.
0 commit comments