versionize 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +23 -0
  2. data/README.md +54 -0
  3. data/lib/versionize.rb +118 -0
  4. metadata +52 -0
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ # Open Works License
2
+
3
+ This is version 0.9.2 of the Open Works License.
4
+
5
+ ## Terms
6
+
7
+ Permission is hereby granted by the copyright holder(s), author(s), and
8
+ contributor(s) of this work, to any person who obtains a copy of this work in
9
+ any form, to reproduce, modify, distribute, publish, sell, use, or otherwise
10
+ deal in the licensed material without restriction, provided the following
11
+ conditions are met:
12
+
13
+ Redistributions, modified or unmodified, in whole or in part, must retain
14
+ applicable copyright notices, the above license notice, these conditions, and
15
+ the following disclaimer.
16
+
17
+ NO WARRANTY OF ANY KIND IS IMPLIED BY, OR SHOULD BE INFERRED FROM, THIS LICENSE
18
+ OR THE ACT OF DISTRIBUTION UNDER THE TERMS OF THIS LICENSE, INCLUDING BUT NOT
19
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
20
+ AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF
22
+ CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE
23
+ WORK, OR THE USE OF OR OTHER DEALINGS IN THE WORK.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Versionize
2
+
3
+ I wanted simple version capabilities. Here they are.
4
+
5
+
6
+ ## usage
7
+
8
+ Using Versionize is dead simple right now. First require and include it, then
9
+ define your version hash, and finally use the methods Versionize provides:
10
+
11
+ #!/usr/bin/env ruby
12
+ require 'versionize'
13
+
14
+ class Foo
15
+ include Versionize
16
+ @version = {
17
+ :major => 1,
18
+ :minor => 0,
19
+ :revision => 2
20
+ }
21
+ end
22
+
23
+ Foo.version
24
+ Foo.version(:array)
25
+ Foo.version(:hash)
26
+ Foo.major
27
+ Foo.major(:string)
28
+ Foo.minor
29
+ Foo.minor(:string)
30
+ Foo.revision
31
+ Foo.revision(:string)
32
+
33
+ The return values from this example are:
34
+
35
+ => "1.0.2"
36
+ => [1, 0, 2]
37
+ => {:major=>1, :minor=>0, :revision=>2}
38
+ => 1
39
+ => "1"
40
+ => 0
41
+ => "0"
42
+ => 2
43
+ => "2"
44
+
45
+ That's about all there is to it.
46
+
47
+
48
+ ## credits
49
+
50
+ This program was written by Chad Perrin, Copyright 2012. It can be
51
+ redistributed under the terms of the Open Works License (see LICENSE file).
52
+ More information about the OWL can be found at:
53
+
54
+ http://owl.apotheon.org
data/lib/versionize.rb ADDED
@@ -0,0 +1,118 @@
1
+ =begin rdoc
2
+
3
+ Versionize provides a simple version management and reporting interface for
4
+ Ruby projects. Include the Versionize module in your class, set the @version
5
+ variable, and start using the version method. Away you go.
6
+
7
+ =end
8
+
9
+ module Versionize
10
+ def self.included(base)
11
+ base.extend(ClassMethods)
12
+ end
13
+
14
+ =begin
15
+
16
+ The +@version" hash is the core of Versionize. Set the values of the three
17
+ sub-versions (+:major+, +:minor+, and +:revision+) to desired values.
18
+
19
+ =end
20
+
21
+ @version = {
22
+ :major => 1,
23
+ :minor => 0,
24
+ :revision => 0
25
+ }
26
+
27
+ module ClassMethods
28
+
29
+ =begin
30
+
31
+ The +version+ method takes one optional argument +format+, indicating the type
32
+ of data you want the method to return (+:array+, +:hash+, or +:string+). The
33
+ default format is +:string+. The return value includes all three sub-versions.
34
+
35
+ Examples:
36
+
37
+ Versionize.version
38
+ => "0.0.1"
39
+
40
+ Versionize.version(:array)
41
+ => [0,0,1]
42
+
43
+ Versionize.version(:hash)
44
+ => {:major=>0,:minor=>0,:revision=>1}
45
+
46
+ =end
47
+
48
+ def version(format=:string)
49
+ case format
50
+ when :array
51
+ [ @version[:major], @version[:minor], @version[:revision] ]
52
+ when :hash
53
+ @version
54
+ when :string
55
+ version(:array).collect {|n| n.to_s }.join '.'
56
+ end
57
+ end
58
+
59
+ =begin
60
+
61
+ The +major+ method takes one optional argument +format+, indicating the type of
62
+ data you want the method to return (+:integer+ or +:string+). The default
63
+ format is +:integer+. The return value includes only the +:major+ sub-version.
64
+
65
+ Examples:
66
+
67
+ Versionize.major
68
+ => 0
69
+
70
+ Versionize.major(:string)
71
+ => "0"
72
+
73
+ =end
74
+
75
+ def major(format=:integer)
76
+ case format
77
+ when :integer
78
+ @version[:major]
79
+ when :string
80
+ @version[:major].to_s
81
+ end
82
+ end
83
+
84
+ =begin
85
+
86
+ The +minor+ method operates just like the +major+ method except that its return
87
+ value includes only the +:minor+ sub-version.
88
+
89
+ =end
90
+
91
+ def minor(format=:integer)
92
+ case format
93
+ when :integer
94
+ @version[:minor]
95
+ when :string
96
+ @version[:minor].to_s
97
+ end
98
+ end
99
+
100
+ =begin
101
+
102
+ The +revision+ method operates just like the +major+ method except that its
103
+ return value includes only the +:revision+ sub-version.
104
+
105
+ =end
106
+
107
+ def revision(format=:integer)
108
+ case format
109
+ when :integer
110
+ @version[:revision]
111
+ when :string
112
+ @version[:revision].to_s
113
+ end
114
+ end
115
+ end
116
+
117
+ extend ClassMethods
118
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: versionize
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chad Perrin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! ' Versionize exists to provide simple version management and reporting.
15
+
16
+ '
17
+ email: code@apotheon.net
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE
23
+ - README.md
24
+ - lib/versionize.rb
25
+ homepage: http://versionize.fossrec.com
26
+ licenses:
27
+ - OWL
28
+ post_install_message: ! ' Thank you for using Versionize. See the rdoc for details.
29
+
30
+ '
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 1.8.15
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Versionize - simple software versions
52
+ test_files: []