class Rondabot::Version

Constants

SemVerRegExp

Attributes

major[RW]
minor[RW]
patch[RW]
pre[RW]
version[RW]

Public Class Methods

make(str_versions) click to toggle source

Cria uma lista de Version com base na string semântica exemplo:

str => ">=1.1.7 <2.0.0 || >=2.0.1"
vira => [Rondabot::Version[1.1.7], Rondabot::Version[2.0.0], Rondabot::Version[2.0.1]]
# File lib/module/Version.rb, line 63
def self.make str_versions
  cleared_versions = str_versions.gsub(/[^a-zA-Z0-9_\.]+/, ",").split(",")
  
  versions = []
  cleared_versions.each do |v|
    if valid(v)
      versions << Version.new(v)
    end
  end
  return versions
end
max(versions) click to toggle source

Static Methods

# File lib/module/Version.rb, line 43
def self.max versions
  ordered = versions.sort_by { |s| Gem::Version.new(s.version) }
  return ordered.last
end
min(versions) click to toggle source
# File lib/module/Version.rb, line 48
def self.min versions
  ordered = versions.sort_by { |s| Gem::Version.new(s.version) }
  return ordered.first
end
new(version_str) click to toggle source
# File lib/module/Version.rb, line 15
def initialize version_str
  v = version_str.match(SemVerRegExp)

  raise ArgumentError.new("#{version_str} is not a valid SemVer Version (http://semver.org)") if v.nil?
  @major = v[1].to_i
  @minor = v[2].to_i
  @patch = v[3].to_i
  @pre = v[4]
  @build = v[5]
  @version = version_str
end
next(current_version, patched_versions) click to toggle source

A próxima versão é a mínima maior do que a atual

# File lib/module/Version.rb, line 78
def self.next(current_version, patched_versions)
  biggest_versions = []
  ordered = patched_versions.sort_by { |s| Gem::Version.new(s.version) }
  ordered.each do |v|
    # Versões maiores do que a versão atual são adicionada no array
    if v.gt?(current_version.version)
      biggest_versions << v
    end
  end
  return min(biggest_versions)
end
valid(str) click to toggle source
# File lib/module/Version.rb, line 53
def self.valid str
  return str.match(SemVerRegExp)
end

Public Instance Methods

eq?(other_version) click to toggle source
# File lib/module/Version.rb, line 37
def eq? other_version
  compare(other_version) == 0
end
gt?(other_version) click to toggle source

Public Methods

# File lib/module/Version.rb, line 29
def gt? other_version
  compare(other_version) > 0
end
lt?(other_version) click to toggle source
# File lib/module/Version.rb, line 33
def lt? other_version
  compare(other_version) < 0
end

Private Instance Methods

compare(other_version) click to toggle source

Private Methods

# File lib/module/Version.rb, line 93
def compare other_version
  other_version = Version.new(other_version)
  return Gem::Version.new(self.version) <=> Gem::Version.new(other_version.version)
end