gem

package module
v0.0.0-...-8eed6fe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2020 License: Apache-2.0 Imports: 5 Imported by: 6

README

go-gem-version

Test Go Report Card GitHub

go-gem-version is a library for parsing RubyGems versions and version constraints, and verifying versions against a set of constraints. go-gem-version can sort a collection of versions properly, handles prerelease versions, etc.

Versions used with go-gem-version must follow RubyGems versioning policy.

For more details, see version.rb and requirement.rb.

Usage

Version Parsing and Comparison

See example

v1, _ := gem.NewVersion("1.2.a")
v2, _ := gem.NewVersion("1.2")

// Comparison example. There is also GreaterThan, Equal, and just
// a simple Compare that returns an int allowing easy >=, <=, etc.
if v1.LessThan(v2) {
	fmt.Printf("%s is less than %s", v1, v2)
}
Version Constraints

See example

v, _ := gem.NewVersion("2.1")
c, _ := gem.NewConstraints(">= 1.0, < 1.4 || > 2.0")

if c.Check(v) {
	fmt.Printf("%s satisfies constraints '%s'", v, c)
}
Version Sorting

See example

versionsRaw := []string{"1.1", "0.7.1", "1.4.a", "1.4.a.1", "1.4", "1.4.0.1"}
versions := make([]gem.Version, len(versionsRaw))
for i, raw := range versionsRaw {
	v, _ := gem.NewVersion(raw)
	versions[i] = v
}

// After this, the versions are properly sorted
sort.Sort(gem.Collection(versions))

Pessimistic Operator

  • ~> 3.0 := >= 3.0, < 4.0
  • ~> 3.0.0 := >= 3.0.0, < 3.1
  • ~> 3.5 := >= 3.5, < 4.0
  • ~> 3.5.0 := >= 3.5.0, < 3.6
  • ~> 3 := >= 3.0, < 4.0

For more details, see here

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrInvalidSemVer is returned when a given version is invalid
	ErrInvalidVersion = xerrors.New("invalid gem version")
)

Functions

This section is empty.

Types

type Collection

type Collection []Version

Collection is a type that implements the sort.Interface interface so that versions can be sorted.

func (Collection) Len

func (v Collection) Len() int

func (Collection) Less

func (v Collection) Less(i, j int) bool

func (Collection) Swap

func (v Collection) Swap(i, j int)

type Constraints

type Constraints [][]constraint

Constraints is one or more constraint that a version can be checked against.

func NewConstraints

func NewConstraints(v string) (Constraints, error)

NewConstraints parses a given constraint and returns a new instance of Constraints

func (Constraints) Check

func (cs Constraints) Check(v Version) bool

Check tests if a version satisfies all the constraints.

func (Constraints) String

func (cs Constraints) String() string

Returns the string format of the constraints

type Version

type Version struct {
	// contains filtered or unexported fields
}

func (Version) Bump

func (v Version) Bump() Version

Bump returns a new version object where the next to the last revision number is one greater (e.g., 5.3.1 => 5.4). https://docs.ruby-lang.org/en/2.6.0/Gem/Version.html#method-i-release

func (Version) Compare

func (v Version) Compare(other Version) int

Compare compares this version to another version. This returns -1, 0, or 1 if this version is smaller, equal, or larger than the other version, respectively.

func (Version) Equal

func (v Version) Equal(o Version) bool

Equal tests if two versions are equal.

func (Version) GreaterThan

func (v Version) GreaterThan(o Version) bool

GreaterThan tests if this version is greater than another version.

func (Version) GreaterThanOrEqual

func (v Version) GreaterThanOrEqual(o Version) bool

GreaterThanOrEqual tests if this version is greater than or equal to another version.

func (Version) LessThan

func (v Version) LessThan(o Version) bool

LessThan tests if this version is less than another version.

func (Version) LessThanOrEqual

func (v Version) LessThanOrEqual(o Version) bool

LessThanOrEqual tests if this version is less than or equal to another version.

func (Version) Release

func (v Version) Release() Version

Release returns the release for this version (e.g. 1.2.0.a -> 1.2.0). Non-prerelease versions return themselves. https://docs.ruby-lang.org/en/2.6.0/Gem/Version.html#method-i-release

func (Version) String

func (v Version) String() string

String returns the full version string

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL