Class: Bundler::AsOf::VersionFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/as_of.rb

Instance Method Summary collapse

Constructor Details

#initialize(dependency, as_of_date) ⇒ VersionFinder

Returns a new instance of VersionFinder.



80
81
82
83
# File 'lib/bundler/as_of.rb', line 80

def initialize(dependency, as_of_date)
  @dependency = dependency
  @as_of_date = as_of_date
end

Instance Method Details

#gem_releasesObject



100
101
102
103
104
# File 'lib/bundler/as_of.rb', line 100

def gem_releases
  @gem_releases ||=
    JSON.parse(::URI.parse(gem_url).open.read)
      .map { |r| ReleaseWrapper.new(@dependency.name, r) }
end

#gem_urlObject



106
107
108
# File 'lib/bundler/as_of.rb', line 106

def gem_url
  @gem_url ||= "https://rubygems.org/api/v1/versions/#{@dependency.name}.json"
end

#releasesObject



93
94
95
96
97
98
# File 'lib/bundler/as_of.rb', line 93

def releases
  gem_releases
    .select { |r| r.date <= @as_of_date }
    .sort_by { |r| [r.date, r.version] }
    .reverse
end

#resolveObject



85
86
87
88
89
90
91
# File 'lib/bundler/as_of.rb', line 85

def resolve
  releases.each do |release|
    next if release.prerelease
    return release if @dependency.requirement.satisfied_by?(release.version)
  end
  nil
end