Module: AnnotateGem::SpecFinder

Extended by:
SpecFinder
Included in:
SpecFinder
Defined in:
lib/annotate_gem/spec_finder.rb

Instance Method Summary collapse

Instance Method Details

#fetch_specs_for(gem_lines) {|processing, total| ... } ⇒ Object

Yields:

  • (processing, total)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/annotate_gem/spec_finder.rb', line 20

def fetch_specs_for(gem_lines)
  total = gem_lines.length
  processing = 0
  yield processing, total if block_given?
  fetcher = bundler_fetcher
  versions = get_versions(fetcher, gem_lines.collect(&:name))
  gem_lines.each do |gem_line|
    processing += 1
    yield processing, total if block_given?
    gem_versions = versions.select { |v| v.first == gem_line.name }
    next if gem_versions.empty? # couldn't find version on RubyGems so go to next one
    version = find_latest_version(gem_versions)
    platform = find_latest_version_platform(gem_versions)
    gem_line.spec = fetcher.fetch_spec([gem_line.name, version, platform])
  end
end

#find_latest_version(versions) ⇒ Object



37
38
39
# File 'lib/annotate_gem/spec_finder.rb', line 37

def find_latest_version(versions)
  versions.sort_by { |v| v[1] }.last[1]
end

#find_latest_version_platform(versions) ⇒ Object



41
42
43
# File 'lib/annotate_gem/spec_finder.rb', line 41

def find_latest_version_platform(versions)
  versions.sort_by { |v| v[1] }.last[2]
end

#find_matching_specs_for(gem_lines) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/annotate_gem/spec_finder.rb', line 12

def find_matching_specs_for(gem_lines)
  gem_lines.each do |line|
    matching_specs = Gem::Dependency.new(line.name).matching_specs
    # TODO: need to find latest
    line.spec = matching_specs.first if matching_specs.any?
  end
end

#find_specs_for(gem_lines, &block) ⇒ Object



5
6
7
8
9
10
# File 'lib/annotate_gem/spec_finder.rb', line 5

def find_specs_for(gem_lines, &block)
  gem_lines = Array(gem_lines)
  find_matching_specs_for(gem_lines)
  gems_to_fetch = gem_lines.select { |gem_line| gem_line.spec.nil? }
  fetch_specs_for(gems_to_fetch, &block) if gems_to_fetch.any?
end