versionomy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ === 0.0.1 / 2008-10-20
2
+
3
+ * Initial test release
data/Manifest.txt ADDED
@@ -0,0 +1,16 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/versionomy.rb
6
+ lib/versionomy/errors.rb
7
+ lib/versionomy/schema.rb
8
+ lib/versionomy/format.rb
9
+ lib/versionomy/value.rb
10
+ lib/versionomy/standard.rb
11
+ lib/versionomy/version.rb
12
+ tests/tc_standard_basic.rb
13
+ tests/tc_standard_bump.rb
14
+ tests/tc_standard_change.rb
15
+ tests/tc_standard_comparison.rb
16
+ tests/tc_standard_parse.rb
data/README.txt ADDED
@@ -0,0 +1,134 @@
1
+ == Versionomy
2
+
3
+ Versionomy is a generalized version number library.
4
+ It provides tools to represent, manipulate, parse, and compare version
5
+ numbers in the wide variety of versioning schemes in use.
6
+
7
+ === Some examples
8
+
9
+ v1 = Versionomy.parse('1.3.2')
10
+ v1.major # => 1
11
+ v1.minor # => 3
12
+ v1.tiny # => 2
13
+
14
+ v2 = Versionomy.parse('1.4a3')
15
+ v2.major # => 1
16
+ v2.minor # => 4
17
+ v2.tiny # => 0
18
+ v2.release_type # => :alpha
19
+ v2.alpha_version # => 3
20
+ v2 > v1 # => true
21
+
22
+ v3 = Versionomy.parse('1.4.0b2')
23
+ v3.major # => 1
24
+ v3.minor # => 4
25
+ v3.tiny # => 0
26
+ v3.release_type # => :beta
27
+ v3.alpha_version # raises NameError
28
+ v3.beta_version # => 2
29
+ v3 > v2 # => true
30
+ v3.to_s # => '1.4.0b2'
31
+
32
+ v4 = v3.bump(:beta_version)
33
+ v4.to_s # => '1.4.0b3'
34
+
35
+ v5 = v3.bump(:release_type)
36
+ v5.to_s # => '1.4.0rc1'
37
+
38
+ v6 = v3.bump(:tiny)
39
+ v6.to_s # => '1.4.1'
40
+
41
+ v7 = v3.bump(:major)
42
+ v7.to_s # => '2.0.0'
43
+ v7.parse_params[:required_fields] = 2
44
+ v7.to_s # => '2.0'
45
+
46
+ v8 = Versionomy.parse('2.0.0.0')
47
+ v8.to_s # => '2.0.0.0'
48
+ v8 == v7 # => true
49
+
50
+ v9 = v7.bump(:patchlevel)
51
+ v9.to_s # => '2.0-1'
52
+
53
+ v10 = Versionomy.parse('2008 SP2', :patchlevel_separator => ' SP')
54
+ v10.major # => 2008
55
+ v10.minor # => 0
56
+ v10.patchlevel # => 2
57
+ v10.to_s # => '2008 SP2'
58
+ v10.unparse(:patchlevel_separator => 'p', :required_fields => 2) # => '2008.0p2'
59
+
60
+ === Feature list
61
+
62
+ Versionomy's default versioning scheme handles four primary fields (labeled
63
+ +major+, +minor+, +tiny+, and +tiny2+). It also supports prerelease versions
64
+ such as "pre", development, alpha, beta, and release candidate. Finally, it
65
+ supports patchlevel numbers for released versions.
66
+
67
+ Versionomy can compare any two version numbers, and "bump" versions at any
68
+ level. It supports parsing and unparsing in most commonly-used formats, and
69
+ allows you to extend the parsing to include custom formats.
70
+
71
+ Finally, Versionomy also lets you to specify any arbitrary versioning
72
+ "schema". You can define any number of version number fields, and provide
73
+ your own semantics and behavior for comparing, parsing, and modifying
74
+ version numbers.
75
+
76
+ === Requirements
77
+
78
+ * Ruby 1.8.7 or later.
79
+ * Rubygems
80
+ * mixology gem.
81
+ * blockenspiel gem.
82
+
83
+ === Installation
84
+
85
+ sudo gem install versionomy
86
+
87
+ === Known issues and limitations
88
+
89
+ * Not yet compatible with Ruby 1.9 due to issues with the mixology gem.
90
+ * JRuby status not yet known.
91
+
92
+ === Development and support
93
+
94
+ Documentation is available at http://virtuoso.rubyforge.org/versionomy
95
+
96
+ Source code is hosted by Github at http://github.com/dazuma/versionomy/tree
97
+
98
+ Report bugs on RubyForge at http://rubyforge.org/projects/virtuoso
99
+
100
+ Contact the author at dazuma at gmail dot com.
101
+
102
+ === Author / Credits
103
+
104
+ Versionomy is written by Daniel Azuma (http://www.daniel-azuma.com).
105
+
106
+ == LICENSE:
107
+
108
+ Copyright 2008 Daniel Azuma.
109
+
110
+ All rights reserved.
111
+
112
+ Redistribution and use in source and binary forms, with or without
113
+ modification, are permitted provided that the following conditions are met:
114
+
115
+ * Redistributions of source code must retain the above copyright notice,
116
+ this list of conditions and the following disclaimer.
117
+ * Redistributions in binary form must reproduce the above copyright notice,
118
+ this list of conditions and the following disclaimer in the documentation
119
+ and/or other materials provided with the distribution.
120
+ * Neither the name of the copyright holder, nor the names of any other
121
+ contributors to this software, may be used to endorse or promote products
122
+ derived from this software without specific prior written permission.
123
+
124
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
125
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
126
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
127
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
128
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
129
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
130
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
131
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
132
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
133
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
134
+ POSSIBILITY OF SUCH DAMAGE.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Versionomy Rakefile
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2008 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+
35
+
36
+ require 'rubygems'
37
+ require 'hoe'
38
+ require File.expand_path("#{File.dirname(__FILE__)}/lib/versionomy.rb")
39
+
40
+ Hoe.new('versionomy', Versionomy::VERSION_STRING) do |p_|
41
+ p_.rubyforge_name = 'virtuoso'
42
+ p_.developer('Daniel Azuma', 'dazuma@gmail.com')
43
+ p_.author = ['Daniel Azuma']
44
+ p_.email = ['dazuma@gmail.com']
45
+ p_.test_globs = ['tests/tc_*.rb']
46
+ p_.extra_deps = [['blockenspiel', '>= 0.0.1']]
47
+ p_.description_sections = ['versionomy']
48
+ p_.url = 'http://virtuoso.rubyforge.org/versionomy'
49
+ end
@@ -0,0 +1,107 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Versionomy exceptions
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2008 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ module Versionomy
38
+
39
+
40
+ # This is a namespace for errors that can be thrown by Versionomy.
41
+
42
+ module Errors
43
+
44
+
45
+ # Base class for all Versionomy exceptions
46
+
47
+ class VersionomyError < RuntimeError
48
+ end
49
+
50
+
51
+ # This exception is raised if parsing or unparsing failed.
52
+
53
+ class ParseError < VersionomyError
54
+ end
55
+
56
+
57
+ # This exception is raised if you try to set a value that is not
58
+ # allowed by the schema.
59
+
60
+ class IllegalValueError < VersionomyError
61
+ end
62
+
63
+
64
+ # This exception is raised during parsing if the specified format
65
+ # name is not recognized.
66
+
67
+ class UnknownFormatError < VersionomyError
68
+ end
69
+
70
+
71
+ # Base class for all Versionomy schema creation exceptions
72
+
73
+ class SchemaCreationError < VersionomyError
74
+ end
75
+
76
+
77
+ # This exception is raised during schema creation if you try to add
78
+ # the same symbol twice to the same symbolic field.
79
+
80
+ class SymbolRedefinedError < SchemaCreationError
81
+ end
82
+
83
+
84
+ # This exception is raised during schema creation if you try to
85
+ # create two subschemas covering overlapping ranges.
86
+
87
+ class RangeOverlapError < SchemaCreationError
88
+ end
89
+
90
+
91
+ # This exception is raised during schema creation if the range
92
+ # specification cannot be interpreted.
93
+
94
+ class RangeSpecificationError < SchemaCreationError
95
+ end
96
+
97
+
98
+ # This exception is raised during schema creation if you try to
99
+ # add a symbol to a non-symbolic schema.
100
+
101
+ class TypeMismatchError < SchemaCreationError
102
+ end
103
+
104
+
105
+ end
106
+
107
+ end
@@ -0,0 +1,132 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Versionomy format
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2008 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ module Versionomy
38
+
39
+
40
+ # This module is a namespace for tools that may be used to build formatters.
41
+
42
+ module Format
43
+
44
+
45
+ # A simple base formatter
46
+
47
+ class Base
48
+
49
+ # Create the formatter.
50
+ # If a block is provided, you may call methods of Versionomy::Format::Builder
51
+ # within the block, to specify ways to parse and unparse.
52
+
53
+ def initialize(&block_)
54
+ @parser = @unparser = nil
55
+ Blockenspiel.invoke(block_, Versionomy::Format::Builder.new(self))
56
+ end
57
+
58
+
59
+ def _set_parser(block_) # :nodoc:
60
+ @parser = block_
61
+ end
62
+
63
+ def _set_unparser(block_) # :nodoc:
64
+ @unparser = block_
65
+ end
66
+
67
+
68
+ # A simple parse algorithm.
69
+ # If a parser block was provided during initialization, calls that block.
70
+ # Otherwise, attempts to parse using "." as a delimiter.
71
+
72
+ def parse(schema_, string_, params_)
73
+ if @parser
74
+ @parser.call(schema_, string_, params_)
75
+ else
76
+ array_ = string_.split('.')
77
+ Versionomy::Value.new(schema_, array_)
78
+ end
79
+ end
80
+
81
+
82
+ # A simple parse algorithm.
83
+ # If an unparser block was provided during initialization, calls that block.
84
+ # Otherwise, attempts to unparse using "." as a delimiter.
85
+
86
+ def unparse(schema_, value_, params_)
87
+ if @unparser
88
+ @unparser.call(schema_, value_, params_)
89
+ else
90
+ value_.value_array.join('.')
91
+ end
92
+ end
93
+
94
+ end
95
+
96
+
97
+ # These methods are available in an initializer block for Versionomy::Format::Base.
98
+
99
+ class Builder < Blockenspiel::Base
100
+
101
+ def initialize(format_) # :nodoc:
102
+ @format = format_
103
+ end
104
+
105
+
106
+ # Specify how to parse a string into a version value.
107
+ #
108
+ # The block should take three parameters: a schema, a string, and a parameters hash.
109
+ # The block should return an object of type Versionomy::Value.
110
+ # You may raise Versionomy::Errors::ParseError if parsing failed.
111
+
112
+ def to_parse(&block_)
113
+ @format._set_parser(block_)
114
+ end
115
+
116
+
117
+ # Specify how to represent a version value as a string.
118
+ #
119
+ # The block should take three parameters: a schema, a Versionomy::Value, and a parameters hash.
120
+ # The block should return a string.
121
+ # You may raise Versionomy::Errors::ParseError if unparsing failed.
122
+
123
+ def to_unparse(&block_)
124
+ @format._set_unparser(block_)
125
+ end
126
+
127
+ end
128
+
129
+
130
+ end
131
+
132
+ end