@@ -28,19 +28,10 @@ module Livecheck
28
28
] . freeze , T ::Array [ String ] )
29
29
private_constant :UNSTABLE_VERSION_KEYWORDS
30
30
31
- sig { returns ( T ::Hash [ T ::Class [ T . anything ] , String ] ) }
32
- private_class_method def self . livecheck_strategy_names
33
- return T . must ( @livecheck_strategy_names ) if defined? ( @livecheck_strategy_names )
34
-
35
- # Cache demodulized strategy names, to avoid repeating this work
36
- @livecheck_strategy_names = T . let ( { } , T . nilable ( T ::Hash [ T ::Class [ T . anything ] , String ] ) )
37
- Strategy . constants . sort . each do |const_symbol |
38
- constant = Strategy . const_get ( const_symbol )
39
- next unless constant . is_a? ( Class )
40
-
41
- T . must ( @livecheck_strategy_names ) [ constant ] = Utils . demodulize ( T . must ( constant . name ) )
42
- end
43
- T . must ( @livecheck_strategy_names ) . freeze
31
+ sig { params ( strategy_class : T ::Class [ T . anything ] ) . returns ( String ) }
32
+ private_class_method def self . livecheck_strategy_names ( strategy_class )
33
+ @livecheck_strategy_names ||= T . let ( { } , T . nilable ( T ::Hash [ T ::Class [ T . anything ] , String ] ) )
34
+ @livecheck_strategy_names [ strategy_class ] ||= Utils . demodulize ( T . must ( strategy_class . name ) )
44
35
end
45
36
46
37
# Uses `formulae_and_casks_to_check` to identify taps in use other than
@@ -668,7 +659,9 @@ def self.latest_version(
668
659
block_provided : livecheck_strategy_block . present? ,
669
660
)
670
661
strategy = Strategy . from_symbol ( livecheck_strategy ) || strategies . first
671
- strategy_name = livecheck_strategy_names [ strategy ]
662
+ next unless strategy
663
+
664
+ strategy_name = livecheck_strategy_names ( strategy )
672
665
673
666
if strategy . respond_to? ( :preprocess_url )
674
667
url = strategy . preprocess_url ( url )
@@ -686,7 +679,7 @@ def self.latest_version(
686
679
puts "URL Options: #{ livecheck_url_options } " if livecheck_url_options . present?
687
680
puts "URL (processed): #{ url } " if url != original_url
688
681
if strategies . present? && verbose
689
- puts "Strategies: #{ strategies . map { |s | livecheck_strategy_names [ s ] } . join ( ", " ) } "
682
+ puts "Strategies: #{ strategies . map { |s | livecheck_strategy_names ( s ) } . join ( ", " ) } "
690
683
end
691
684
puts "Strategy: #{ strategy_name } " if strategy . present?
692
685
puts "Regex: #{ livecheck_regex . inspect } " if livecheck_regex . present?
@@ -823,7 +816,7 @@ def self.latest_version(
823
816
version_info [ :meta ] [ :url ] [ :homebrew_curl ] = homebrew_curl if homebrew_curl . present?
824
817
end
825
818
version_info [ :meta ] [ :strategy ] = strategy_name if strategy . present?
826
- version_info [ :meta ] [ :strategies ] = strategies . map { |s | livecheck_strategy_names [ s ] } if strategies . present?
819
+ version_info [ :meta ] [ :strategies ] = strategies . map { |s | livecheck_strategy_names ( s ) } if strategies . present?
827
820
version_info [ :meta ] [ :regex ] = regex . inspect if regex . present?
828
821
version_info [ :meta ] [ :cached ] = true if strategy_data [ :cached ] == true
829
822
version_info [ :meta ] [ :throttle ] = livecheck_throttle if livecheck_throttle
@@ -892,7 +885,9 @@ def self.resource_version(
892
885
block_provided : livecheck_strategy_block . present? ,
893
886
)
894
887
strategy = Strategy . from_symbol ( livecheck_strategy ) || strategies . first
895
- strategy_name = livecheck_strategy_names [ strategy ]
888
+ next unless strategy
889
+
890
+ strategy_name = livecheck_strategy_names ( strategy )
896
891
897
892
if strategy . respond_to? ( :preprocess_url )
898
893
url = strategy . preprocess_url ( url )
@@ -910,7 +905,7 @@ def self.resource_version(
910
905
puts "URL Options: #{ livecheck_url_options } " if livecheck_url_options . present?
911
906
puts "URL (processed): #{ url } " if url != original_url
912
907
if strategies . present? && verbose
913
- puts "Strategies: #{ strategies . map { |s | livecheck_strategy_names [ s ] } . join ( ", " ) } "
908
+ puts "Strategies: #{ strategies . map { |s | livecheck_strategy_names ( s ) } . join ( ", " ) } "
914
909
end
915
910
puts "Strategy: #{ strategy_name } " if strategy . present?
916
911
puts "Regex: #{ livecheck_regex . inspect } " if livecheck_regex . present?
@@ -1032,7 +1027,7 @@ def self.resource_version(
1032
1027
end
1033
1028
resource_version_info [ :meta ] [ :strategy ] = strategy_name if strategy . present?
1034
1029
if strategies . present?
1035
- resource_version_info [ :meta ] [ :strategies ] = strategies . map { |s | livecheck_strategy_names [ s ] }
1030
+ resource_version_info [ :meta ] [ :strategies ] = strategies . map { |s | livecheck_strategy_names ( s ) }
1036
1031
end
1037
1032
resource_version_info [ :meta ] [ :regex ] = regex . inspect if regex . present?
1038
1033
resource_version_info [ :meta ] [ :cached ] = true if cached == true
0 commit comments