Class: Gemsurance::GemInfoRetriever

Inherits:
Object
  • Object
show all
Defined in:
lib/gemsurance/gem_info_retriever.rb

Defined Under Namespace

Classes: GemInfo

Instance Method Summary collapse

Constructor Details

#initialize(specs, dependencies, bundle_definition) ⇒ GemInfoRetriever

Returns a new instance of GemInfoRetriever.



50
51
52
53
54
# File 'lib/gemsurance/gem_info_retriever.rb', line 50

def initialize(specs, dependencies, bundle_definition)
  @specs = specs
  @dependencies = dependencies
  @bundle_definition = bundle_definition
end

Instance Method Details

#retrieve(options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/gemsurance/gem_info_retriever.rb', line 56

def retrieve(options = {})
  gem_infos = []
  
  @specs.each do |current_spec|
    active_spec = @bundle_definition.index[current_spec.name].sort_by { |b| b.version }

    if !current_spec.version.prerelease? && !options[:pre] && active_spec.size > 1
      active_spec = active_spec.delete_if { |b| b.respond_to?(:version) && b.version.prerelease? }
    end

    active_spec = active_spec.last
    next if active_spec.nil?

    gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version)
    git_outdated = current_spec.git_version != active_spec.git_version

    info = ::Gems.info(active_spec.name)
    homepage_uri      = info['homepage_uri']
    documentation_uri = info['documentation_uri']
    source_code_uri   = info['source_code_uri']

    # TODO: handle git versions
    # spec_version    = "#{active_spec.version}#{active_spec.git_version}"
    # current_version = "#{current_spec.version}#{current_spec.git_version}"
    in_gem_file = @dependencies.any?{|d| d.name == active_spec.name}
    if gem_outdated || git_outdated
      gem_infos << GemInfo.new(active_spec.name, current_spec.version, active_spec.version, in_gem_file, homepage_uri, documentation_uri, source_code_uri, GemInfo::STATUS_OUTDATED)
    else
      gem_infos << GemInfo.new(active_spec.name, current_spec.version, current_spec.version, in_gem_file, homepage_uri, documentation_uri, source_code_uri)
    end
  end
  gem_infos
end