Module: Polisher::GemVersions::ClassMethods

Defined in:
lib/polisher/gem/versions.rb

Instance Method Summary collapse

Instance Method Details

#earliest_version_matching(dep) ⇒ Object

Retrieve earliest version matching dep



59
60
61
62
# File 'lib/polisher/gem/versions.rb', line 59

def earliest_version_matching(dep)
  version = versions_matching(dep).collect { |v| ::Gem::Version.new v }.min
  version.nil? ? nil : version.to_s
end

#latest_version_in_target(name, target) ⇒ Object

Return latest version of gem in target



78
79
80
# File 'lib/polisher/gem/versions.rb', line 78

def latest_version_in_target(name, target)
  versions_in_target(name, target).collect { |v| ::Gem::Version.new v }.max
end

#latest_version_matching(dep) ⇒ Object

Retrieve latest version matching dep



53
54
55
56
# File 'lib/polisher/gem/versions.rb', line 53

def latest_version_matching(dep)
  version = versions_matching(dep).collect { |v| ::Gem::Version.new v }.max
  version.nil? ? nil : version.to_s
end

#latest_version_of(name) ⇒ Object

Retieve latest version of gem available on rubygems



41
42
43
# File 'lib/polisher/gem/versions.rb', line 41

def latest_version_of(name)
  remote_versions_for(name).collect { |v| ::Gem::Version.new v }.max.to_s
end

#local_versions_for(name, &bl) ⇒ Array<String>

Retrieve list of the versions of the specified gem installed locally

Parameters:

  • name (String)

    name of the gem to lookup

  • bl (Callable)

    optional block to invoke with versions retrieved

Returns:

  • (Array<String>)

    list of versions of gem installed locally



20
21
22
23
24
25
26
27
# File 'lib/polisher/gem/versions.rb', line 20

def local_versions_for(name, &bl)
  silence_warnings do
    @local_db ||= ::Gem::Specification.all
  end
  versions = @local_db.select { |s| s.name == name }.collect { |s| s.version }
  bl.call(:local_gem, name, versions) unless bl.nil?
  versions
end

#remote_versions_for(name) ⇒ Object

Retrieve all versions of gem available on rubygems



30
31
32
33
34
35
36
37
38
# File 'lib/polisher/gem/versions.rb', line 30

def remote_versions_for(name)
  require 'json'

  client.url = "https://rubygems.org/api/v1/versions/#{name}.json"
  client.follow_location = true
  client.http_get
  json = JSON.parse(client.body_str)
  json.collect { |version| version['number'] }
end

#version_matching_target(dep, target) ⇒ Object

Retrieve version of gem matching target



65
66
67
68
69
# File 'lib/polisher/gem/versions.rb', line 65

def version_matching_target(dep, target)
  version = versions_in_target(dep.name, target).select  { |v| dep.match? dep.name, v }
                                                .collect { |v|   ::Gem::Version.new v }.max
  version.nil? ? nil : version.to_s
end

#versions_in_target(name, target) ⇒ Object

Return versions of gem in target



72
73
74
75
# File 'lib/polisher/gem/versions.rb', line 72

def versions_in_target(name, target)
  require 'polisher/targets'
  Polisher.target(target).versions_for(name)
end

#versions_matching(dep) ⇒ Object

Retrieve versions matching dependency



46
47
48
49
50
# File 'lib/polisher/gem/versions.rb', line 46

def versions_matching(dep)
  remote_versions_for(dep.name).select { |v|
    dep.match? dep.name, v
  }
end