Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Allow array of strings in VersionSet constructor

For the convenience when setting up a set without existing versions.
  • Loading branch information...
commit b4d1ad9407aa05c56f86f8dd10af520250f8137b 1 parent 34552fc
Joe Corcoran authored
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 }

0 comments on commit b4d1ad9

Please sign in to comment.
Something went wrong with that request. Please try again.