Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
Mar 05, 2013
Joe Corcoran Fix return value of version#increment
It was returning [nil, nil] thanks to the syntax used in
34552fc
Joe Corcoran Allow array of strings in VersionSet constructor
For the convenience when setting up a set without existing versions.
b4d1ad9
Joe Corcoran Update readme
With better examples.
6040d99
Joe Corcoran Add Ruby 2.0.0 to Travis config 989462c
1  .travis.yml
@@ -2,6 +2,7 @@ rvm:
2 2 - 1.9.3
3 3 - jruby-19mode
4 4 - rbx-19mode
  5 + - 2.0.0
5 6 script: "rspec"
6 7 notifications:
7 8 email:
16 README.md
Source Rendered
@@ -9,11 +9,11 @@ Utility for working with software versions as specified by [Semantic Versioning
9 9 Create a version object from a SemVer-formatted string.
10 10
11 11 ```ruby
12   -version = SemanticVersioning::Version.new('1.2.0')
  12 +version = SemanticVersioning::Version.new('1.2.0-pre.1+b.42')
13 13 version.major
14 14 # => 1
15 15 version.build
16   - # => nil
  16 + # => "b.42"
17 17 ```
18 18
19 19 Increment version identifiers.
@@ -27,7 +27,7 @@ version
27 27 Compare versions.
28 28
29 29 ```ruby
30   -current = SemanticVersioning::Version.new('1.2.0')
  30 +current = SemanticVersioning::Version.new('1.2.0-pre.1')
31 31 previous = SemanticVersioning::Version.new('1.1.12')
32 32 current > previous
33 33 # => true
@@ -38,12 +38,12 @@ current > previous
38 38 Work with sorted version sets.
39 39
40 40 ```ruby
41   -versions = SemanticVersioning::VersionSet.new([current])
42   - # => #<SemanticVersioning::VersionSet: {1.2.0}>
43   -versions << previous
44   - # => #<SemanticVersioning::VersionSet: {1.1.12, 1.2.0}>
  41 +versions = SemanticVersioning::VersionSet.new(['1.2.0-pre.3', '1.3.0'])
  42 + # => #<SemanticVersioning::VersionSet: {1.2.0-pre.3, 1.3.0}>
  43 +versions << SemanticVersioning::Version.new('1.1.12')
  44 + # => #<SemanticVersioning::VersionSet: {1.1.12, 1.2.0-pre.3, 1.3.0}>
45 45 versions.where(:>=, '1.1.13')
46   - # => #<SemanticVersioning::VersionSet: {1.2.0}>
  46 + # => #<SemanticVersioning::VersionSet: {1.2.0-pre.3, 1.3.0}>
47 47 ```
48 48
49 49 ## License
3  lib/semantic_versioning/version.rb
@@ -84,7 +84,8 @@ def reset(*identifiers)
84 84 end
85 85
86 86 def clear_optional_identifiers
87   - @pre, @build = nil, nil
  87 + @pre = nil
  88 + @build = nil
88 89 end
89 90
90 91 end
7 lib/semantic_versioning/version_set.rb
@@ -4,10 +4,15 @@ module SemanticVersioning
4 4
5 5 class VersionSet < SortedSet
6 6
  7 + def initialize(versions)
  8 + versions.map! { |v| Version.new(v) } if versions.all? { |v| v.is_a?(String) }
  9 + super(versions)
  10 + end
  11 +
7 12 def where(operator, version)
8 13 version = Version.new(version) if version.is_a? String
9 14 subset = select { |v| v.send(operator, version) }
10   - self.class.new subset
  15 + self.class.new(subset)
11 16 end
12 17
13 18 end
11 spec/semantic_versioning/version_set_spec.rb
@@ -2,8 +2,13 @@
2 2
3 3 describe SemanticVersioning::VersionSet do
4 4
5   - let(:versions) { [v('1.0.0'), v('1.0.10'), v('0.10.0')] }
6   - let(:set) { SemanticVersioning::VersionSet.new(versions) }
  5 + let(:versions) { [v('1.0.0'), v('1.0.10'), v('0.10.0')] }
  6 + let(:set_klass) { SemanticVersioning::VersionSet }
  7 + let(:set) { set_klass.new(versions) }
  8 +
  9 + specify 'constructor accepts array of strings' do
  10 + set_klass.new(['1.0.0', '0.9.0']).should == set_klass.new([v('1.0.0'), v('0.9.0')])
  11 + end
7 12
8 13 it 'yields version in correct order' do
9 14 results = set.map{ |v| v }
@@ -20,7 +25,7 @@
20 25 set.where(:<, v('1.0.0')).should be_a SemanticVersioning::VersionSet
21 26 end
22 27 it 'allows version to be given as a string' do
23   - set.where(:<, '1.0.0').first.should be_a SemanticVersioning::Version
  28 + set.where(:<, '1.0.0').should be_a SemanticVersioning::VersionSet
24 29 end
25 30 specify { set.where(:<, v('1.0.10')).length.should == 2 }
26 31 specify { set.where(:<=, v('1.0.10')).length.should == 3 }

No commit comments for this range

Something went wrong with that request. Please try again.