Skip to content
Browse files

Allow array of strings in VersionSet constructor

For the convenience when setting up a set without existing versions.
  • Loading branch information...
1 parent 34552fc commit b4d1ad9407aa05c56f86f8dd10af520250f8137b @joecorcoran committed Mar 5, 2013
Showing with 14 additions and 4 deletions.
  1. +6 −1 lib/semantic_versioning/version_set.rb
  2. +8 −3 spec/semantic_versioning/version_set_spec.rb
View
7 lib/semantic_versioning/version_set.rb
@@ -4,10 +4,15 @@ module SemanticVersioning
class VersionSet < SortedSet
+ def initialize(versions)
+ versions.map! { |v| Version.new(v) } if versions.all? { |v| v.is_a?(String) }
+ super(versions)
+ end
+
def where(operator, version)
version = Version.new(version) if version.is_a? String
subset = select { |v| v.send(operator, version) }
- self.class.new subset
+ self.class.new(subset)
end
end
View
11 spec/semantic_versioning/version_set_spec.rb
@@ -2,8 +2,13 @@
describe SemanticVersioning::VersionSet do
- let(:versions) { [v('1.0.0'), v('1.0.10'), v('0.10.0')] }
- let(:set) { SemanticVersioning::VersionSet.new(versions) }
+ let(:versions) { [v('1.0.0'), v('1.0.10'), v('0.10.0')] }
+ let(:set_klass) { SemanticVersioning::VersionSet }
+ let(:set) { set_klass.new(versions) }
+
+ specify 'constructor accepts array of strings' do
+ set_klass.new(['1.0.0', '0.9.0']).should == set_klass.new([v('1.0.0'), v('0.9.0')])
+ end
it 'yields version in correct order' do
results = set.map{ |v| v }
@@ -20,7 +25,7 @@
set.where(:<, v('1.0.0')).should be_a SemanticVersioning::VersionSet
end
it 'allows version to be given as a string' do
- set.where(:<, '1.0.0').first.should be_a SemanticVersioning::Version
+ set.where(:<, '1.0.0').should be_a SemanticVersioning::VersionSet
end
specify { set.where(:<, v('1.0.10')).length.should == 2 }
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.