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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8aa9e5f86d2b4c6c6f86e7b5377a88ed6d4921cc
4
- data.tar.gz: 511807bc05296390996bf576a2e60f7fe989fac7
3
+ metadata.gz: 21b3c8db30c7ee7ea033ee1094f4d083c05d91b5
4
+ data.tar.gz: 32ebe9aea06834661b8c4c1600d80774df84edbd
5
5
  SHA512:
6
- metadata.gz: dbe293e57f56dd1819826dd8519ae397eaf496d5543eec2dccd4e20c858d994a9604c07dd571c7c0a176e171a77708bc023569e15cea863249c1714bae0fc675
7
- data.tar.gz: a2ba180239e13b8cc9d4f8f51ba7936e971f33cd3f4df67c3cbd10431433eb5a237df7e2c8c1edfc5291e9f197b2dc39db4a4fb2ce1ae64c61537901ec872067
6
+ metadata.gz: 8facb48c8c03629279d0d76582f0749d791e593aa80f1ba23f082385dfcd6d41a93d3608f762a5e50ec99c256c95ea7fce80d7b8d00f504bd28a7cedf5793a1c
7
+ data.tar.gz: 8b725358bc2fcbedd9f22fd26d77183042f0d18e811401e7bd6b715c7248e4ec2c3e20bd5bc8a6b04eda9de1fb2b6fb492d7275a2314ce8ca73ce9cc646eb566
data/Gemfile CHANGED
@@ -24,5 +24,6 @@ end
24
24
 
25
25
  group :test do
26
26
  gem "spork"
27
+ gem "rake"
27
28
  gem "rspec"
28
29
  end
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
@@ -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
  #
@@ -26,4 +26,6 @@ module Semverse
26
26
  "'#{constraint}' did not contain a valid operator or a valid version string."
27
27
  end
28
28
  end
29
+
30
+ class NoSolutionError < SemverseError; end
29
31
  end
@@ -1,3 +1,3 @@
1
1
  module Semverse
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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.0.0
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-05 00:00:00.000000000 Z
11
+ date: 2014-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler