Class: Deliver::AppScreenshotIterator
- Inherits:
-
Object
- Object
- Deliver::AppScreenshotIterator
- Defined in:
- deliver/lib/deliver/app_screenshot_iterator.rb
Overview
This is a convinient class that enumerates app store connect’s screenshots in various degrees.
Constant Summary collapse
- NUMBER_OF_THREADS =
Helper.test? ? 1 : [ENV.fetch("DELIVER_NUMBER_OF_THREADS", 10).to_i, 10].min
Instance Method Summary collapse
-
#each_app_screenshot {|localization, app_screenshot_set, app_screenshot| ... } ⇒ Object
Iterate app_screenshot over localizations and app_screenshot_sets.
-
#each_app_screenshot_set {|localization, app_screenshot_set| ... } ⇒ Object
Iterate app_screenshot_set over localizations.
-
#each_local_screenshot(screenshots_per_language) {|localization, app_screenshot_set, app_screenshot, index| ... } ⇒ Object
Iterate given local app_screenshot over localizations and app_screenshot_sets with index within each app_screenshot_set.
-
#initialize(localizations) ⇒ AppScreenshotIterator
constructor
A new instance of AppScreenshotIterator.
Constructor Details
#initialize(localizations) ⇒ AppScreenshotIterator
Returns a new instance of AppScreenshotIterator.
7 8 9 |
# File 'deliver/lib/deliver/app_screenshot_iterator.rb', line 7 def initialize(localizations) @localizations = localizations end |
Instance Method Details
#each_app_screenshot {|localization, app_screenshot_set, app_screenshot| ... } ⇒ Object
Iterate app_screenshot over localizations and app_screenshot_sets
45 46 47 48 49 50 51 52 53 |
# File 'deliver/lib/deliver/app_screenshot_iterator.rb', line 45 def each_app_screenshot(&block) return enum_for(__method__) unless block_given? each_app_screenshot_set do |localization, app_screenshot_set| app_screenshot_set.app_screenshots.each do |app_screenshot| yield(localization, app_screenshot_set, app_screenshot) end end end |
#each_app_screenshot_set {|localization, app_screenshot_set| ... } ⇒ Object
Iterate app_screenshot_set over localizations
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'deliver/lib/deliver/app_screenshot_iterator.rb', line 16 def each_app_screenshot_set(&block) return enum_for(__method__) unless block_given? # Collect app_screenshot_sets from localizations in parallel but # limit the number of threads working at a time with using `lazy` and `force` controls # to not attack App Store Connect results = @localizations.each_slice(NUMBER_OF_THREADS).lazy.map do |localizations| localizations.map do |localization| Thread.new do [localization, localization.get_app_screenshot_sets] end end end.flat_map do |threads| threads.map { |t| t.join.value } end.force results.each do |localization, app_screenshot_sets| app_screenshot_sets.each do |app_screenshot_set| yield(localization, app_screenshot_set) end end end |
#each_local_screenshot(screenshots_per_language) {|localization, app_screenshot_set, app_screenshot, index| ... } ⇒ Object
Iterate given local app_screenshot over localizations and app_screenshot_sets with index within each app_screenshot_set
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'deliver/lib/deliver/app_screenshot_iterator.rb', line 63 def each_local_screenshot(screenshots_per_language, &block) return enum_for(__method__, screenshots_per_language) unless block_given? # Iterate over all the screenshots per language and display_type # and then enqueue them to worker one by one if it's not duplciated on App Store Connect screenshots_per_language.map do |language, screenshots_for_language| localization = @localizations.find { |l| l.locale == language } [localization, screenshots_for_language] end.reject do |localization, _| localization.nil? end.each do |localization, screenshots_for_language| iterate_over_screenshots_per_language(localization, screenshots_for_language, &block) end end |