YAVM 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +93 -0
- data/bin/version +17 -0
- data/lib/yavm.rb +25 -0
- data/lib/yavm/README.md +93 -0
- data/lib/yavm/command_line.rb +150 -0
- data/lib/yavm/stores.rb +31 -0
- data/lib/yavm/stores/base.rb +46 -0
- data/lib/yavm/stores/bower.rb +26 -0
- data/lib/yavm/stores/gem_spec.rb +39 -0
- data/lib/yavm/stores/package.rb +26 -0
- data/lib/yavm/stores/semver.rb +30 -0
- data/lib/yavm/version.rb +88 -0
- data/lib/yavm/versions.rb +34 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f61250eb85d9a2e91c9e678d3a778af73077f1c
|
4
|
+
data.tar.gz: ce292887c4595dbeb3076e714dfe02aadebff7fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8807b0ea3cfd119a4e50230f0fb8622216d2c5f7522975599f14338fa116bdda25a0f9743f6bd68283f026ba4fea174384b638cdda4593e942e0b00e8c92378e
|
7
|
+
data.tar.gz: dc0afe74765d1e989fb5a39f5e18d48bc29fa20cbb20d52009b71b4c4f57afaccad86398b1c8e4c70b56dbda374ed5c952637f541bd32b84515ba43585a97fa9
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# YAVM: Yet Another Version Manager
|
2
|
+
|
3
|
+
A tiny gem for managing project version numbers.
|
4
|
+
|
5
|
+
Heavily inspired by the `semver` gem, this is a tiny utility for managing version numbers,
|
6
|
+
which includes support for multiple version format stores:
|
7
|
+
|
8
|
+
* The `semver` gem's `.semver` file
|
9
|
+
* node.js `package.json` files
|
10
|
+
* bower `bower.json` files
|
11
|
+
* ruby `.gemspec` files
|
12
|
+
|
13
|
+
With planned support for:
|
14
|
+
|
15
|
+
* Python distutils package support
|
16
|
+
|
17
|
+
# Usage
|
18
|
+
|
19
|
+
*Exhaustive usage patterns can be found at `version help`*
|
20
|
+
|
21
|
+
``` shell
|
22
|
+
# Install
|
23
|
+
$ gem install yavm
|
24
|
+
|
25
|
+
# In a language/framework without a supported versioning system:
|
26
|
+
$ version init
|
27
|
+
$ version # => 0.0.0
|
28
|
+
|
29
|
+
# In an existing project with supported versioning:
|
30
|
+
version # => 0.2.0
|
31
|
+
|
32
|
+
# Basic Usage
|
33
|
+
$ version inc minor # => 0.3.0
|
34
|
+
$ version inc major # => 1.0.0
|
35
|
+
$ version special pre4 # => 1.0.0-pre4
|
36
|
+
$ version special # => 1.0.0
|
37
|
+
$ version meta 20141113 # => 1.0.0 (meta not displayed by default)
|
38
|
+
$ version tag # => v1.0.0+20141113 (useful for version control)
|
39
|
+
$ version format "%M.%m" # => 1.0
|
40
|
+
```
|
41
|
+
|
42
|
+
## Available Format Tags
|
43
|
+
|
44
|
+
Tag | Meaning
|
45
|
+
----|---------------------
|
46
|
+
%M | **M**ajor
|
47
|
+
%m | **M**inor
|
48
|
+
%p | **P**atch
|
49
|
+
%s | **S**pecial
|
50
|
+
%t | Me**t**a
|
51
|
+
%% | Literal % Character
|
52
|
+
|
53
|
+
## Conflict Resolution
|
54
|
+
|
55
|
+
If your project contains multiple supported version "stores", YAVM will keep them in sync.
|
56
|
+
If they go out of sync outside of YAVM, you will be prompted to pick the canonical/authoritative
|
57
|
+
version, and all other stores will be updated.
|
58
|
+
|
59
|
+
``` text
|
60
|
+
$ version
|
61
|
+
Multiple version stores are in use, and aren't consistent.
|
62
|
+
Please select the authoritative version:
|
63
|
+
|
64
|
+
WARNING: File munging is dangerous. A manual resolution might be safer.
|
65
|
+
|
66
|
+
1: 1.0.0 [.semver file]
|
67
|
+
2: 1.0.3 [bower.json file]
|
68
|
+
3: 0.0.0 [gemspec: ./yavm.gemspec]
|
69
|
+
|
70
|
+
Selection: 2
|
71
|
+
Now on 1.0.3
|
72
|
+
```
|
73
|
+
|
74
|
+
# Roadmap
|
75
|
+
|
76
|
+
## Features
|
77
|
+
|
78
|
+
- [x] show version
|
79
|
+
- [x] increment
|
80
|
+
- [x] set special
|
81
|
+
- [x] set meta
|
82
|
+
- [x] formatting
|
83
|
+
- [x] tags
|
84
|
+
- [x] help
|
85
|
+
- [x] package.json support
|
86
|
+
- [x] bower.json support
|
87
|
+
- [ ] when changing version, show new one
|
88
|
+
- [ ] programmatic interface
|
89
|
+
- [ ] tests
|
90
|
+
- [ ] handle invalid version info (see Version#parse)
|
91
|
+
- [ ] 'version init'
|
92
|
+
- [ ] quick mode (when finding versions - short circuit once one is found)
|
93
|
+
- [ ] raise sensible exceptions
|
data/bin/version
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib/', __FILE__)
|
4
|
+
$:.unshift lib unless $:.include?(lib)
|
5
|
+
|
6
|
+
lib = File.expand_path('../../lib/', __FILE__)
|
7
|
+
$:.unshift lib unless $:.include?(lib)
|
8
|
+
|
9
|
+
|
10
|
+
require 'yavm/command_line'
|
11
|
+
|
12
|
+
begin
|
13
|
+
command_line = YAVM::CommandLine.new
|
14
|
+
command_line.invoke!
|
15
|
+
rescue Docopt::Exit => e
|
16
|
+
puts e.message
|
17
|
+
end
|
data/lib/yavm.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.dirname(__FILE__)
|
2
|
+
$:.unshift lib unless $:.include?(lib)
|
3
|
+
|
4
|
+
require 'yavm/version'
|
5
|
+
require 'yavm/stores'
|
6
|
+
|
7
|
+
module YAVM
|
8
|
+
|
9
|
+
def find(quiet = true)
|
10
|
+
versions = YAVM::Stores.locate_versions
|
11
|
+
|
12
|
+
if versions.equal?
|
13
|
+
return versions.first
|
14
|
+
else
|
15
|
+
return nil if quiet
|
16
|
+
|
17
|
+
raise RuntimeError, ''
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
module_function :find
|
24
|
+
|
25
|
+
end
|
data/lib/yavm/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# YAVM: Yet Another Version Manager
|
2
|
+
|
3
|
+
A tiny gem for managing project version numbers.
|
4
|
+
|
5
|
+
Heavily inspired by the `semver` gem, this is a tiny utility for managing version numbers,
|
6
|
+
which includes support for multiple version format stores:
|
7
|
+
|
8
|
+
* The `semver` gem's `.semver` file
|
9
|
+
* node.js `package.json` files
|
10
|
+
* bower `bower.json` files
|
11
|
+
* ruby `.gemspec` files
|
12
|
+
|
13
|
+
With planned support for:
|
14
|
+
|
15
|
+
* Python distutils package support
|
16
|
+
|
17
|
+
# Usage
|
18
|
+
|
19
|
+
*Exhaustive usage patterns can be found at `version help`*
|
20
|
+
|
21
|
+
``` shell
|
22
|
+
# Install
|
23
|
+
$ gem install yavm
|
24
|
+
|
25
|
+
# In a language/framework without a supported versioning system:
|
26
|
+
$ version init
|
27
|
+
$ version # => 0.0.0
|
28
|
+
|
29
|
+
# In an existing project with supported versioning:
|
30
|
+
version # => 0.2.0
|
31
|
+
|
32
|
+
# Basic Usage
|
33
|
+
$ version inc minor # => 0.3.0
|
34
|
+
$ version inc major # => 1.0.0
|
35
|
+
$ version special pre4 # => 1.0.0-pre4
|
36
|
+
$ version special # => 1.0.0
|
37
|
+
$ version meta 20141113 # => 1.0.0 (meta not displayed by default)
|
38
|
+
$ version tag # => v1.0.0+20141113 (useful for version control)
|
39
|
+
$ version format "%M.%m" # => 1.0
|
40
|
+
```
|
41
|
+
|
42
|
+
## Available Format Tags
|
43
|
+
|
44
|
+
Tag | Meaning
|
45
|
+
----|---------------------
|
46
|
+
%M | **M**ajor
|
47
|
+
%m | **M**inor
|
48
|
+
%p | **P**atch
|
49
|
+
%s | **S**pecial
|
50
|
+
%t | Me**t**a
|
51
|
+
%% | Literal % Character
|
52
|
+
|
53
|
+
## Conflict Resolution
|
54
|
+
|
55
|
+
If your project contains multiple supported version "stores", YAVM will keep them in sync.
|
56
|
+
If they go out of sync outside of YAVM, you will be prompted to pick the canonical/authoritative
|
57
|
+
version, and all other stores will be updated.
|
58
|
+
|
59
|
+
``` text
|
60
|
+
$ version
|
61
|
+
Multiple version stores are in use, and aren't consistent.
|
62
|
+
Please select the authoritative version:
|
63
|
+
|
64
|
+
WARNING: File munging is dangerous. A manual resolution might be safer.
|
65
|
+
|
66
|
+
1: 1.0.0 [.semver file]
|
67
|
+
2: 1.0.3 [bower.json file]
|
68
|
+
3: 0.0.0 [gemspec: ./yavm.gemspec]
|
69
|
+
|
70
|
+
Selection: 2
|
71
|
+
Now on 1.0.3
|
72
|
+
```
|
73
|
+
|
74
|
+
# Roadmap
|
75
|
+
|
76
|
+
## Features
|
77
|
+
|
78
|
+
- [x] show version
|
79
|
+
- [x] increment
|
80
|
+
- [x] set special
|
81
|
+
- [x] set meta
|
82
|
+
- [x] formatting
|
83
|
+
- [x] tags
|
84
|
+
- [x] help
|
85
|
+
- [x] package.json support
|
86
|
+
- [x] bower.json support
|
87
|
+
- [ ] when changing version, show new one
|
88
|
+
- [ ] programmatic interface
|
89
|
+
- [ ] tests
|
90
|
+
- [ ] handle invalid version info (see Version#parse)
|
91
|
+
- [ ] 'version init'
|
92
|
+
- [ ] quick mode (when finding versions - short circuit once one is found)
|
93
|
+
- [ ] raise sensible exceptions
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'docopt'
|
2
|
+
require 'yavm/stores'
|
3
|
+
|
4
|
+
module YAVM
|
5
|
+
class CommandLine
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@invocation = File.basename($0)
|
9
|
+
end
|
10
|
+
|
11
|
+
def invoke!
|
12
|
+
@args = Docopt::docopt(doc)
|
13
|
+
command = @args.select { |a, v| commands.include?(a) && v }.keys.first
|
14
|
+
command = 'show' if command.nil?
|
15
|
+
|
16
|
+
versions = YAVM::Stores.locate_versions
|
17
|
+
|
18
|
+
if versions.empty? && !@args['init']
|
19
|
+
puts "There doesn't seem to be any versioning information on this project."
|
20
|
+
puts "Use native versioning tools (see docs for support), or run `#{@invocation} init`"
|
21
|
+
puts "to use the default versioning method."
|
22
|
+
exit(1)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Commands which use the version information require it to be consistent
|
26
|
+
if version_commands.include? command
|
27
|
+
choose_authoritative!(versions) unless versions.equal?
|
28
|
+
version = versions.first
|
29
|
+
end
|
30
|
+
|
31
|
+
case command
|
32
|
+
when 'show'
|
33
|
+
puts "#{version}"
|
34
|
+
|
35
|
+
when 'inc'
|
36
|
+
if @args['major']
|
37
|
+
version.major += 1
|
38
|
+
version.minor = version.patch = 0
|
39
|
+
version.special = version.meta = nil
|
40
|
+
|
41
|
+
elsif @args['minor']
|
42
|
+
version.minor += 1
|
43
|
+
version.patch = 0
|
44
|
+
version.special = version.meta = nil
|
45
|
+
|
46
|
+
elsif @args['patch']
|
47
|
+
version.patch += 1
|
48
|
+
version.special = version.meta = nil
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
versions.set_all!(version)
|
53
|
+
|
54
|
+
when 'special'
|
55
|
+
version.special = @args['<string>']
|
56
|
+
|
57
|
+
versions.set_all!(version)
|
58
|
+
|
59
|
+
when 'meta'
|
60
|
+
version.meta = @args['<string>']
|
61
|
+
|
62
|
+
versions.set_all!(version)
|
63
|
+
|
64
|
+
when 'format'
|
65
|
+
puts "#{version.format(@args['<string>'])}"
|
66
|
+
|
67
|
+
when 'tag'
|
68
|
+
puts "#{version.tag}"
|
69
|
+
|
70
|
+
when 'help'
|
71
|
+
Docopt::Exit.set_usage(nil)
|
72
|
+
raise Docopt::Exit, doc.strip
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def choose_authoritative!(versions)
|
80
|
+
puts "Multiple version stores are in use, and aren't consistent."
|
81
|
+
puts " Please select the authoritative version:\n\n"
|
82
|
+
puts "WARNING: File munging is dangerous. A manual resolution might be safer.\n\n"
|
83
|
+
|
84
|
+
selection = ''
|
85
|
+
|
86
|
+
while selection.is_a? String
|
87
|
+
versions.each_with_index do |version, index|
|
88
|
+
puts " %3s: %-15s [%s]" % [index+1, version, version.store.name]
|
89
|
+
end
|
90
|
+
|
91
|
+
print "\nSelection: "
|
92
|
+
selection = STDIN.gets.chomp
|
93
|
+
|
94
|
+
if selection.to_i.to_s == selection && (1..versions.size) === selection.to_i
|
95
|
+
selection = selection.to_i
|
96
|
+
break
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
authoritative_version = versions[selection.to_i - 1]
|
101
|
+
|
102
|
+
versions.set_all!(authoritative_version)
|
103
|
+
|
104
|
+
puts "Now on #{authoritative_version}"
|
105
|
+
exit(0)
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
def doc
|
110
|
+
<<-DOCOPT.gsub(/^ {6}/, '')
|
111
|
+
YAVM. Yet Another Version Manager
|
112
|
+
|
113
|
+
Usage:
|
114
|
+
#{@invocation}
|
115
|
+
#{@invocation} inc (major|minor|patch)
|
116
|
+
#{@invocation} special [<string>]
|
117
|
+
#{@invocation} meta [<string>]
|
118
|
+
#{@invocation} format <string>
|
119
|
+
#{@invocation} tag
|
120
|
+
#{@invocation} help
|
121
|
+
|
122
|
+
Options:
|
123
|
+
inc Increment a specific version number
|
124
|
+
special Set a special (eg: pre-release) suffix
|
125
|
+
meta Set a metadata version suffix
|
126
|
+
format Display version in specific format (%M, %m, %p, %s, %t)
|
127
|
+
tag Equivalent to format 'v%M.%m.%p%s'
|
128
|
+
help Show this screen.
|
129
|
+
|
130
|
+
DOCOPT
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# A list of arguments which should be considered commands.
|
135
|
+
# We should only ever see one of these at a time, typically.
|
136
|
+
#
|
137
|
+
def commands
|
138
|
+
version_commands + support_commands
|
139
|
+
end
|
140
|
+
|
141
|
+
def version_commands
|
142
|
+
['show', 'inc', 'special', 'meta', 'format', 'tag']
|
143
|
+
end
|
144
|
+
|
145
|
+
def support_commands
|
146
|
+
['help']
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
data/lib/yavm/stores.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'yavm/versions'
|
2
|
+
|
3
|
+
require 'yavm/stores/semver'
|
4
|
+
require 'yavm/stores/package'
|
5
|
+
require 'yavm/stores/bower'
|
6
|
+
require 'yavm/stores/gem_spec'
|
7
|
+
|
8
|
+
module YAVM
|
9
|
+
module Stores
|
10
|
+
|
11
|
+
def stores
|
12
|
+
[
|
13
|
+
YAVM::Stores::Semver,
|
14
|
+
YAVM::Stores::Package,
|
15
|
+
YAVM::Stores::Bower,
|
16
|
+
YAVM::Stores::GemSpec,
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
def locate_versions
|
21
|
+
versions = stores.map do |store|
|
22
|
+
store = store.new
|
23
|
+
next store.to_version if store.exists?
|
24
|
+
end
|
25
|
+
|
26
|
+
YAVM::Versions.new(versions)
|
27
|
+
end
|
28
|
+
|
29
|
+
module_function :locate_versions, :stores
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module YAVM
|
4
|
+
module Stores
|
5
|
+
|
6
|
+
class Base
|
7
|
+
def name
|
8
|
+
self.class.name
|
9
|
+
end
|
10
|
+
#
|
11
|
+
# If the file for the store exists.
|
12
|
+
# Only 1 file must match the glob.
|
13
|
+
#
|
14
|
+
def exists?
|
15
|
+
Dir[glob].length == 1
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Fetch the matched filename for this store
|
20
|
+
#
|
21
|
+
def filename
|
22
|
+
Dir[glob].first if exists?
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
class GenericJSON < YAVM::Stores::Base
|
28
|
+
|
29
|
+
def data
|
30
|
+
@data ||= JSON.parse(IO.read(filename))
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_version
|
34
|
+
Version.new(self, version_key)
|
35
|
+
end
|
36
|
+
|
37
|
+
def set!(new_version)
|
38
|
+
@data = update_version_key(new_version.to_s)
|
39
|
+
File.open(filename, 'w') { |f| f.write JSON.pretty_generate(data) }
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'yavm/stores/base'
|
2
|
+
|
3
|
+
module YAVM
|
4
|
+
module Stores
|
5
|
+
class Bower < YAVM::Stores::GenericJSON
|
6
|
+
|
7
|
+
def name
|
8
|
+
'bower.json file'
|
9
|
+
end
|
10
|
+
|
11
|
+
def glob
|
12
|
+
'./bower.json'
|
13
|
+
end
|
14
|
+
|
15
|
+
def version_key
|
16
|
+
data['version']
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_version_key(what)
|
20
|
+
data['version'] = what
|
21
|
+
return data
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yavm/version'
|
3
|
+
require 'yavm/stores/base'
|
4
|
+
|
5
|
+
module YAVM
|
6
|
+
module Stores
|
7
|
+
class GemSpec < YAVM::Stores::Base
|
8
|
+
|
9
|
+
def name
|
10
|
+
"gemspec: #{filename}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def glob
|
14
|
+
'./*.gemspec'
|
15
|
+
end
|
16
|
+
|
17
|
+
def spec
|
18
|
+
@spec ||= Gem::Specification.load(filename)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_version
|
22
|
+
Version.new(self, spec.version.to_s.gsub('.pre.', '-'))
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# Munge the existing file to replace the version identifier.
|
27
|
+
# This might be a bit brittle.
|
28
|
+
#
|
29
|
+
def set!(new_version)
|
30
|
+
current_spec = IO.read(filename)
|
31
|
+
spec_token = current_spec.match(/Gem::Specification.new do \|(?<token>[^\|]+)\|/m)['token']
|
32
|
+
new_spec = current_spec.gsub(/^(\s+#{spec_token}\.version\s+=\s+)("|')([^"']+)(\2)/, "\\1\\2#{new_version}\\4")
|
33
|
+
|
34
|
+
File.open(filename, 'w') { |f| f.write new_spec }
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'yavm/stores/base'
|
2
|
+
|
3
|
+
module YAVM
|
4
|
+
module Stores
|
5
|
+
class Package < YAVM::Stores::GenericJSON
|
6
|
+
|
7
|
+
def name
|
8
|
+
'npm package.json'
|
9
|
+
end
|
10
|
+
|
11
|
+
def glob
|
12
|
+
'./package.json'
|
13
|
+
end
|
14
|
+
|
15
|
+
def version_key
|
16
|
+
data['version']
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_version_key(what)
|
20
|
+
data['version'] = what
|
21
|
+
return data
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'yavm/stores/base'
|
3
|
+
|
4
|
+
module YAVM
|
5
|
+
module Stores
|
6
|
+
class Semver < YAVM::Stores::Base
|
7
|
+
|
8
|
+
def name
|
9
|
+
'.semver file'
|
10
|
+
end
|
11
|
+
|
12
|
+
def glob
|
13
|
+
'./.semver'
|
14
|
+
end
|
15
|
+
|
16
|
+
def data
|
17
|
+
@data ||= YAML.load_file(filename)
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_version
|
21
|
+
Version.new(self, data)
|
22
|
+
end
|
23
|
+
|
24
|
+
def set!(new_version)
|
25
|
+
File.open(filename, 'w') { |f| f.write new_version.to_yaml }
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/yavm/version.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module YAVM
|
5
|
+
class Version
|
6
|
+
extend ::Forwardable
|
7
|
+
|
8
|
+
attr_accessor :store
|
9
|
+
|
10
|
+
def initialize(store, vobject = nil)
|
11
|
+
self.store = store
|
12
|
+
|
13
|
+
if vobject
|
14
|
+
case vobject
|
15
|
+
when String
|
16
|
+
parse(vobject)
|
17
|
+
when Hash
|
18
|
+
load(vobject)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
format('%M.%m.%p%s')
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_hash
|
28
|
+
@_version.marshal_dump
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_yaml
|
32
|
+
@_version.marshal_dump.to_yaml
|
33
|
+
end
|
34
|
+
|
35
|
+
def tag
|
36
|
+
format('v%M.%m.%p%s%t')
|
37
|
+
end
|
38
|
+
|
39
|
+
def format(string = '')
|
40
|
+
string = string.dup
|
41
|
+
|
42
|
+
string.gsub!('%M', major.to_s)
|
43
|
+
string.gsub!('%m', minor.to_s)
|
44
|
+
string.gsub!('%p', patch.to_s)
|
45
|
+
string.gsub!('%s', special ? "-#{special}" : '')
|
46
|
+
string.gsub!('%t', meta ? "+#{meta}" : '')
|
47
|
+
string.gsub!('%%', '%')
|
48
|
+
|
49
|
+
return string
|
50
|
+
end
|
51
|
+
|
52
|
+
def ==(other)
|
53
|
+
self.major == other.major &&
|
54
|
+
self.minor == other.minor &&
|
55
|
+
self.patch == other.patch &&
|
56
|
+
self.special == other.special
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def parse(string)
|
62
|
+
match = string.match(/\A(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:-(?<special>[a-z0-9]+))?(?:\+(?<meta>[a-z0-9]+))?\z/i)
|
63
|
+
|
64
|
+
@_version = Hash[ match.names.zip( match.captures ) ]
|
65
|
+
@_version = OpenStruct.new(@_version)
|
66
|
+
integerize!
|
67
|
+
end
|
68
|
+
|
69
|
+
def load(hash)
|
70
|
+
@_version = OpenStruct.new(hash)
|
71
|
+
integerize!
|
72
|
+
end
|
73
|
+
|
74
|
+
def integerize!
|
75
|
+
@_version.major = @_version.major.to_i
|
76
|
+
@_version.minor = @_version.minor.to_i
|
77
|
+
@_version.patch = @_version.patch.to_i
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# Allows calling "version.minor" and the like on the Version instance
|
82
|
+
#
|
83
|
+
def_delegators :@_version,
|
84
|
+
:major, :minor, :patch, :special, :meta,
|
85
|
+
:major=, :minor=, :patch=, :special=, :meta=
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module YAVM
|
4
|
+
class Versions
|
5
|
+
extend ::Forwardable
|
6
|
+
|
7
|
+
def initialize(versions)
|
8
|
+
self.versions = versions.compact
|
9
|
+
end
|
10
|
+
|
11
|
+
# Set a given version to be the authoritative version for all defined stores
|
12
|
+
def set_all!(authoritative_version)
|
13
|
+
versions.each do |version|
|
14
|
+
version.store.set!(authoritative_version)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Get a list of versions which aren't the same version
|
20
|
+
# as the first version, and boolean-ify that result
|
21
|
+
#
|
22
|
+
def equal?
|
23
|
+
versions.reject { |v| v == versions.first }.length.zero?
|
24
|
+
end
|
25
|
+
|
26
|
+
def_delegators :versions, :<<, :length, :size, :[],
|
27
|
+
:first, :each, :each_with_index, :empty?, :any?
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_accessor :versions
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: YAVM
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lewis Eason
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: docopt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.0
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.5.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.5.0
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.5.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: json
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.8.0
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.8.1
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.8.0
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.8.1
|
53
|
+
description: A tiny gem for managing project version numbers
|
54
|
+
email: me@lewiseason.co.uk
|
55
|
+
executables:
|
56
|
+
- version
|
57
|
+
extensions: []
|
58
|
+
extra_rdoc_files: []
|
59
|
+
files:
|
60
|
+
- README.md
|
61
|
+
- bin/version
|
62
|
+
- lib/yavm.rb
|
63
|
+
- lib/yavm/README.md
|
64
|
+
- lib/yavm/command_line.rb
|
65
|
+
- lib/yavm/stores.rb
|
66
|
+
- lib/yavm/stores/base.rb
|
67
|
+
- lib/yavm/stores/bower.rb
|
68
|
+
- lib/yavm/stores/gem_spec.rb
|
69
|
+
- lib/yavm/stores/package.rb
|
70
|
+
- lib/yavm/stores/semver.rb
|
71
|
+
- lib/yavm/version.rb
|
72
|
+
- lib/yavm/versions.rb
|
73
|
+
homepage: https://github.com/lewiseason/yavm
|
74
|
+
licenses:
|
75
|
+
- GPLv2
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.2.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Yet Another Version Manager
|
97
|
+
test_files: []
|
98
|
+
has_rdoc:
|