versionub 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
+ #
4
+ # This file is part of versionub.
5
+ #
6
+ # versionub is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # versionub is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with versionub. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'versionub/type'
21
+
22
+ module Versionub
23
+ Types = {}
24
+
25
+ def self.parse (text, type=:standard)
26
+ Types[type.to_sym].parse(text.to_s)
27
+ end
28
+
29
+ def self.register (type, &block)
30
+ Types[type.to_sym] = Versionub::Type.new(type.to_sym, &block)
31
+ end
32
+ end
33
+
34
+ require 'versionub/types/standard'
@@ -0,0 +1,86 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
+ #
4
+ # This file is part of versionub.
5
+ #
6
+ # versionub is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # versionub is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with versionub. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'parslet'
21
+
22
+ module Versionub
23
+
24
+ class Type
25
+ class Instance
26
+ attr_reader :type
27
+
28
+ def initialize (type, text, data)
29
+ @type = type
30
+ @text = text
31
+ @data = data
32
+ end
33
+
34
+ def to_hash
35
+ @data.clone
36
+ end
37
+
38
+ def to_s
39
+ @text
40
+ end
41
+ end
42
+
43
+ attr_reader :name
44
+
45
+ def initialize (name, &block)
46
+ @name = name
47
+ @instance = Class.new(Instance)
48
+
49
+ instance_eval &block
50
+ end
51
+
52
+ def parse (text)
53
+ data = parser.new.parse(text)
54
+
55
+ if transformer
56
+ data = transformer.apply(data)
57
+ end
58
+
59
+ @instance.new(name, text, data)
60
+ end
61
+
62
+ def parser (&block)
63
+ if block
64
+ @parser = Class.new(Parslet::Parser)
65
+ @parser.class_eval(&block)
66
+ end
67
+
68
+ @parser
69
+ end
70
+
71
+ def transformer (&block)
72
+ if block
73
+ @transformer = Class.new(Parslet::Transform)
74
+ @transformer.class_eval(&block)
75
+ end
76
+
77
+ @transformer
78
+ end
79
+
80
+ def callbacks (&block)
81
+ @instance.class_eval &block
82
+ @instance.instance_methods
83
+ end
84
+ end
85
+
86
+ end
@@ -0,0 +1,128 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
+ #
4
+ # This file is part of versionub.
5
+ #
6
+ # versionub is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # versionub is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with versionub. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ Versionub.register :standard do
21
+ parser do
22
+ rule(:part) { match['0-9'].repeat }
23
+
24
+ rule(:separator) { match['.-_\s'] }
25
+
26
+ rule(:version) {
27
+ part.as(:major) >> separator.maybe >>
28
+ part.maybe.as(:minor) >> separator.maybe >>
29
+ part.maybe.as(:bugfix) >> separator.maybe >> (
30
+ ((str('d') | str('development') | str('dev')) >>
31
+ (part.as(:development) | any.as(:development))) |
32
+
33
+ ((str('a') | str('alpha') | str('alfa')) >>
34
+ (part.as(:alpha) | any.as(:alpha))) |
35
+
36
+ ((str('b') | str('beta')) >>
37
+ (part.as(:beta) | any.as(:beta))) |
38
+
39
+ ((str('rc')) >>
40
+ (part.as(:rc) | any.as(:rc)))
41
+ ).maybe
42
+ }
43
+
44
+ root :version
45
+ end
46
+
47
+ callbacks do
48
+ def major
49
+ @data[:major].to_s if @data[:major]
50
+ end
51
+
52
+ def minor
53
+ @data[:minor].to_s if @data[:minor]
54
+ end
55
+
56
+ def bugfix
57
+ @data[:bugfix].to_s if @data[:bugfix]
58
+ end
59
+
60
+ def release_candidate
61
+ @data[:rc].is_a?(Array) ? '0' : @data[:rc].to_s
62
+ end; alias rc release_candidate
63
+
64
+ def development
65
+ @data[:development].is_a?(Array) ? '0' : @data[:development].to_s
66
+ end; alias d development; alias dev development;
67
+
68
+ def alpha
69
+ @data[:alpha].is_a?(Array) ? '0' : @data[:alpha].to_s
70
+ end; alias a alpha; alias alfa alpha
71
+
72
+ def beta
73
+ @data[:beta].is_a?(Array) ? '0' : @data[:beta].to_s
74
+ end; alias b beta
75
+
76
+ def release_candidate?
77
+ !!@data[:rc]
78
+ end
79
+
80
+ def development?
81
+ !!@data[:development]
82
+ end
83
+
84
+ def alpha?
85
+ !!@data[:alpha]
86
+ end
87
+
88
+ def beta?
89
+ !!@data[:beta]
90
+ end
91
+
92
+ include Comparable
93
+
94
+ def <=> (value)
95
+ value = Versionub.parse(value)
96
+
97
+ if release_candidate? && value.release_candidate? && (tmp = (rc <=> value.rc))
98
+ return tmp
99
+ end
100
+
101
+ if development? && value.development? && (tmp = (development <=> value.development))
102
+ return tmp
103
+ end
104
+
105
+ if alpha? && value.alpha? && (tmp = (alpha <=> value.alpha))
106
+ return tmp
107
+ end
108
+
109
+ if beta? && value.beta? && (tmp = (beta <=> value.beta))
110
+ return tmp
111
+ end
112
+
113
+ if (tmp = (bugfix <=> value.bugfix)) != 0
114
+ return tmp
115
+ end
116
+
117
+ if (tmp = (minor <=> value.minor)) != 0
118
+ return tmp
119
+ end
120
+
121
+ if (tmp = (major <=> value.major)) != 0
122
+ return tmp
123
+ end
124
+
125
+ 0
126
+ end
127
+ end
128
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: versionub
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - meh.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-29 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: parslet
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ description:
27
+ email: meh@paranoici.org
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files: []
33
+
34
+ files:
35
+ - lib/versionub.rb
36
+ - lib/versionub/types/standard.rb
37
+ - lib/versionub/type.rb
38
+ homepage: http://github.com/meh/versionub
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.4
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: A library to manage version strings.
65
+ test_files: []
66
+