semverse 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +3 -0
- data/lib/semverse/constraint.rb +38 -0
- data/lib/semverse/errors.rb +2 -0
- data/lib/semverse/gem_version.rb +1 -1
- data/lib/semverse/version.rb +0 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21b3c8db30c7ee7ea033ee1094f4d083c05d91b5
|
4
|
+
data.tar.gz: 32ebe9aea06834661b8c4c1600d80774df84edbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8facb48c8c03629279d0d76582f0749d791e593aa80f1ba23f082385dfcd6d41a93d3608f762a5e50ec99c256c95ea7fce80d7b8d00f504bd28a7cedf5793a1c
|
7
|
+
data.tar.gz: 8b725358bc2fcbedd9f22fd26d77183042f0d18e811401e7bd6b715c7248e4ec2c3e20bd5bc8a6b04eda9de1fb2b6fb492d7275a2314ce8ca73ce9cc646eb566
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
[![Gem Version](http://img.shields.io/gem/v/semverse.svg)][gem]
|
3
3
|
[![Build Status](http://img.shields.io/travis/berkshelf/semverse.svg)][travis]
|
4
4
|
|
5
|
+
[gem]: https://rubygems.org/gems/semverse
|
6
|
+
[travis]: http://travis-ci.org/berkshelf/semverse
|
7
|
+
|
5
8
|
An elegant library for representing and comparing SemVer versions and constraints
|
6
9
|
|
7
10
|
## Installation
|
data/lib/semverse/constraint.rb
CHANGED
@@ -14,6 +14,44 @@ module Semverse
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
# Returns all of the versions which satisfy all of the given constraints
|
18
|
+
#
|
19
|
+
# @param [Array<Semverse::Constraint>, Array<String>] constraints
|
20
|
+
# @param [Array<Semverse::Version>, Array<String>] versions
|
21
|
+
#
|
22
|
+
# @return [Array<Semverse::Version>]
|
23
|
+
def satisfy_all(constraints, versions)
|
24
|
+
constraints = Array(constraints).collect do |con|
|
25
|
+
con.is_a?(Constraint) ? con : Constraint.new(con)
|
26
|
+
end.uniq
|
27
|
+
|
28
|
+
versions = Array(versions).collect do |ver|
|
29
|
+
ver.is_a?(Version) ? ver : Version.new(ver)
|
30
|
+
end.uniq
|
31
|
+
|
32
|
+
versions.select do |ver|
|
33
|
+
constraints.all? { |constraint| constraint.satisfies?(ver) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Return the best version from the given list of versions for the given list of constraints
|
38
|
+
#
|
39
|
+
# @param [Array<Semverse::Constraint>, Array<String>] constraints
|
40
|
+
# @param [Array<Semverse::Version>, Array<String>] versions
|
41
|
+
#
|
42
|
+
# @raise [NoSolutionError] if version matches the given constraints
|
43
|
+
#
|
44
|
+
# @return [Semverse::Version]
|
45
|
+
def satisfy_best(constraints, versions)
|
46
|
+
solution = satisfy_all(constraints, versions)
|
47
|
+
|
48
|
+
if solution.empty?
|
49
|
+
raise NoSolutionError
|
50
|
+
end
|
51
|
+
|
52
|
+
solution.sort.last
|
53
|
+
end
|
54
|
+
|
17
55
|
# Split a constraint string into an Array of two elements. The first
|
18
56
|
# element being the operator and second being the version string.
|
19
57
|
#
|
data/lib/semverse/errors.rb
CHANGED
data/lib/semverse/gem_version.rb
CHANGED
data/lib/semverse/version.rb
CHANGED
@@ -29,23 +29,6 @@ module Semverse
|
|
29
29
|
raise InvalidVersionFormat.new(version_string)
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
33
|
-
# Convert the argument to a Version object if it isn't one already.
|
34
|
-
# Creating version objects from Strings involves expensive Regexp
|
35
|
-
# processing, so this improves performance when dealing with objects that
|
36
|
-
# may be instances of Version.
|
37
|
-
# @param version_or_string [Version, #to_s] the object to coerce to a
|
38
|
-
# Version.
|
39
|
-
# @return [Version] either the version object you gave or a new one if
|
40
|
-
# you gave a String.
|
41
|
-
def coerce(version_or_string)
|
42
|
-
if version_or_string.kind_of?(self)
|
43
|
-
version_or_string
|
44
|
-
else
|
45
|
-
new(version_or_string.to_s)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
32
|
end
|
50
33
|
|
51
34
|
include Comparable
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semverse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Winsor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|