33module PolishOpenSourceRank
44 module Web
55 class Composition
6- # Expands one canonical ranking path into every non-empty paginated URL.
7- module SitemapPageSeries
8- module_function
9-
10- def paths ( path )
11- paths = [ path ]
12- 2 . upto ( Presentation ::RankingPaginator ::MAX_PAGE ) do |page |
13- break if yield ( ( page - 1 ) * Presentation ::RankingPaginator ::PER_PAGE ) . empty?
14-
15- paths << "#{ path } /page/#{ page } "
16- end
17- paths
18- end
19- end
20-
21- # Couples one canonical path with the query that determines its non-empty pages.
22- class SitemapQuerySeries
23- def initialize ( path , query )
24- @path = path
25- @query = query
26- end
27-
28- def paths ( reader )
29- SitemapPageSeries . paths ( path ) do |offset |
30- reader . call ( **query , limit : 1 , offset : offset )
31- end
32- end
33-
34- private
35-
36- attr_reader :path , :query
37- end
38-
396 # Combines independently owned ranking URL inventories.
407 class SitemapRankingCatalog
418 def initialize ( catalogs :)
@@ -57,16 +24,6 @@ class PublicRankingSitemapCatalog
5724 Route = Data . define ( :kind , :metric , :suffix )
5825 # Binds a ranking route to its public prefix, geographic scope, and snapshot.
5926 Scope = Data . define ( :prefix , :slug , :period_start ) do
60- def series ( route )
61- SitemapQuerySeries . new (
62- "#{ prefix } /#{ route . suffix } " ,
63- scope : slug ,
64- kind : route . kind ,
65- metric : route . metric ,
66- period_start : period_start
67- )
68- end
69-
7027 def people_prefix
7128 slug == 'poland' ? '/people' : "/people/locations/#{ slug } "
7229 end
@@ -105,18 +62,12 @@ def ranking_scopes
10562 %w[ organization-repositories trending repositories/trending ]
10663 ] . map { |values | Route . new ( *values ) } . freeze
10764
108- def initialize ( show_ranking_detail :)
109- @show_ranking_detail = show_ranking_detail
110- end
111-
11265 def paths ( latest_period :, period_slugs :)
11366 latest_paths ( latest_period ) + period_slugs . flat_map { |slug | historical_paths ( slug ) }
11467 end
11568
11669 private
11770
118- attr_reader :show_ranking_detail
119-
12071 def latest_paths ( period_start )
12172 latest_scope_paths ( Scope . new ( nil , 'poland' , period_start ) ) +
12273 city_slugs . flat_map do |slug |
@@ -149,11 +100,7 @@ def historical_city_indexes(prefix)
149100 end
150101
151102 def route_paths ( scope , routes )
152- routes . flat_map { |route | route_page_paths ( scope , route ) }
153- end
154-
155- def route_page_paths ( scope , route )
156- scope . series ( route ) . paths ( show_ranking_detail )
103+ routes . map { |route | "#{ scope . prefix } /#{ route . suffix } " }
157104 end
158105
159106 def city_slugs
@@ -165,27 +112,17 @@ def city_slugs
165112 class LanguageRankingSitemapCatalog
166113 # Binds language ranking metrics to a public period prefix and snapshot.
167114 Period = Data . define ( :prefix , :start ) do
168- def series ( metric )
169- SitemapQuerySeries . new (
170- "#{ prefix } /languages/#{ metric . slug } " ,
171- metric : metric . key ,
172- period_start : start
173- )
115+ def path ( metric )
116+ "#{ prefix } /languages/#{ metric . slug } "
174117 end
175118 end
176119
177- def initialize ( show_language_ranking_detail :)
178- @show_language_ranking_detail = show_language_ranking_detail
179- end
180-
181120 def paths ( latest_period :, period_slugs :)
182121 current_paths ( latest_period ) + period_slugs . flat_map { |slug | historical_paths ( slug ) }
183122 end
184123
185124 private
186125
187- attr_reader :show_language_ranking_detail
188-
189126 def current_paths ( latest_period )
190127 latest_period ? period_paths ( Period . new ( '' , latest_period ) ) : [ ]
191128 end
@@ -201,7 +138,7 @@ def period_paths(period)
201138 end
202139
203140 def metric_paths ( period , metric )
204- period . series ( metric ) . paths ( show_language_ranking_detail )
141+ period . path ( metric )
205142 end
206143 end
207144
@@ -215,27 +152,21 @@ def ecosystem(name)
215152 end
216153 # Owns package metric URL generation for one ecosystem and snapshot.
217154 Ecosystem = Data . define ( :path , :name , :period_start ) do
218- def paths ( reader )
155+ def paths
219156 [ path ] + Contexts ::Packages ::Domain ::PackageRankingMetric . all ( ecosystem : name ) . flat_map do |metric |
220- metric_paths ( metric , reader )
157+ metric_path ( metric )
221158 end
222159 end
223160
224161 private
225162
226- def metric_paths ( metric , reader )
227- SitemapQuerySeries . new (
228- "#{ path } /#{ metric . slug } " ,
229- ecosystem : name ,
230- metric : metric . key ,
231- period_start : period_start
232- ) . paths ( reader )
163+ def metric_path ( metric )
164+ "#{ path } /#{ metric . slug } "
233165 end
234166 end
235167
236- def initialize ( package_ranking_read_model :, show_package_ranking_detail : )
168+ def initialize ( package_ranking_read_model :)
237169 @package_ranking_read_model = package_ranking_read_model
238- @show_package_ranking_detail = show_package_ranking_detail
239170 end
240171
241172 def paths ( latest_period :, period_slugs :)
@@ -244,7 +175,7 @@ def paths(latest_period:, period_slugs:)
244175
245176 private
246177
247- attr_reader :package_ranking_read_model , :show_package_ranking_detail
178+ attr_reader :package_ranking_read_model
248179
249180 def current_paths ( latest_period )
250181 latest_period ? period_paths ( Period . new ( '' , latest_period ) ) : [ ]
@@ -265,7 +196,7 @@ def ecosystems(period)
265196 end
266197
267198 def ecosystem_paths ( period , ecosystem )
268- period . ecosystem ( ecosystem ) . paths ( show_package_ranking_detail )
199+ period . ecosystem ( ecosystem ) . paths
269200 end
270201
271202 def package_ranking_ecosystem? ( ecosystem )
0 commit comments