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.



112
113
114
115
116
# File 'lib/gemsurance/gem_info_retriever.rb', line 112

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

Instance Method Details

#retrieve(options = {}) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/gemsurance/gem_info_retriever.rb', line 118

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