Class: GemStats::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_stats/fetcher.rb

Constant Summary collapse

@@bulk_number =
50

Class Method Summary collapse

Class Method Details

.fetch_and_safeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gem_stats/fetcher.rb', line 17

def self.fetch_and_safe
  pbar = ProgressBar.new("Fetching gems", list.count)
  pbar.bar_mark = '#'
  threads = []
  list_names.each_with_index do |name, index|
    threads << Thread.new(name) { |name| GemInfo.new(name).save }
    if threads.count == @@bulk_number
      threads.each(&:join)
      threads = []
      pbar.inc(bulk_number)
    end
  end
  threads.each(&:join)
  pbar.inc(bulk_number)
  pbar.finish
end

.list(all_versions = false, prerelease = false) ⇒ Object



9
10
11
# File 'lib/gem_stats/fetcher.rb', line 9

def self.list(all_versions = false, prerelease = false)
  @gem_list ||= ::Gem::SpecFetcher.new.list(all_versions, prerelease).values.flatten(1)
end

.list_namesObject



13
14
15
# File 'lib/gem_stats/fetcher.rb', line 13

def self.list_names
  @list_name ||= list.map(&:first).uniq.compact
end