Module: Jira::Auto::Tool::Helpers::Pagination
- Defined in:
- lib/jira/auto/tool/helpers/pagination.rb
Constant Summary collapse
- PAGE_SIZE =
50- PAGINATION_PARAMETER_STYLES =
{ camelCase: %i[maxResults startAt], snake_case: %i[max_results start_at] }.freeze
Class Method Summary collapse
- .build_pagination_options(parameter_naming_convention, max_results, start_at) ⇒ Object
- .fetch_all_object_pages(parameter_naming_convention = :camelCase) ⇒ Object
Class Method Details
.build_pagination_options(parameter_naming_convention, max_results, start_at) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/jira/auto/tool/helpers/pagination.rb', line 35 def self.(parameter_naming_convention, max_results, start_at) PAGINATION_PARAMETER_STYLES .fetch(parameter_naming_convention) { |k| "#{k.inspect}: not found in #{PAGINATION_PARAMETER_STYLES}" } .zip([max_results, start_at]) .to_h end |
.fetch_all_object_pages(parameter_naming_convention = :camelCase) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jira/auto/tool/helpers/pagination.rb', line 10 def self.fetch_all_object_pages(parameter_naming_convention = :camelCase) all_objects = [] start_at = 0 loop do = (parameter_naming_convention, PAGE_SIZE, start_at) log.debug { "Fetching objects from Jira (#{.inspect})..." } fetched_objects = yield() log.debug { "Fetched #{fetched_objects.size} object." } all_objects.concat(fetched_objects) start_at += PAGE_SIZE break if fetched_objects.empty? end log.debug { all_objects.collect(&:name).join(", ") } all_objects end |