Module: Builderator::Control::Version::Comparable

Includes:
Comparable
Included in:
Builderator::Control::Version
Defined in:
lib/builderator/control/version/comparable.rb

Overview

Sort earliest -> latest (Array.last -> latest (e.g. 1.0.0), Array.first -> earliest(e.g. 0.0.1))

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/builderator/control/version/comparable.rb', line 11

def <=>(other)
  ## Simple version comparison
  return major <=> other.major unless same?(:major, other)
  return minor <=> other.minor unless same?(:minor, other)
  return patch <=> other.patch unless same?(:patch, other)

  ## Prereleases: prerelease < non-prerelease
  return compare(:is_prerelease, other) if one?(:is_prerelease, other)

  if both?(:is_prerelease, other)
    ## This is a little sketchy... We're assuming that pre-releases
    ## have a lexicological order.
    return prerelease_name <=> other.prerelease_name unless same?(:prerelease_name, other)
    return prerelease_iteration <=> other.prerelease_iteration unless same?(:prerelease_iteration, other)
  end

  ## Build number. With build number > without build number
  compare(:build, other)
end