semver2 3.3.2 → 3.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.semver +1 -1
- data/lib/dsl.rb +59 -0
- data/lib/runner.rb +26 -31
- metadata +4 -3
data/.semver
CHANGED
data/lib/dsl.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module XSemVer
|
2
|
+
|
3
|
+
module DSL
|
4
|
+
|
5
|
+
def self.included(klass)
|
6
|
+
klass.extend ClassMethods
|
7
|
+
klass.send :include, InstanceMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
class CommandError < StandardError
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
module InstanceMethods
|
17
|
+
|
18
|
+
# Calls an instance method defined via the ::command class method.
|
19
|
+
# Raises CommandError if the command does not exist.
|
20
|
+
def run_command(command)
|
21
|
+
method_name = "#{self.class.command_prefix}#{command}"
|
22
|
+
if self.class.method_defined?(method_name)
|
23
|
+
send method_name
|
24
|
+
else
|
25
|
+
raise CommandError, "invalid command #{command}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
module ClassMethods
|
35
|
+
|
36
|
+
# Defines an instance method based on the first command name.
|
37
|
+
# The method executes the code of the given block.
|
38
|
+
# Aliases methods for any subsequent command names.
|
39
|
+
def command(*command_names, &block)
|
40
|
+
method_name = "#{command_prefix}#{command_names.shift}"
|
41
|
+
define_method method_name, &block
|
42
|
+
command_names.each do |c|
|
43
|
+
alias_method "#{command_prefix}#{c}", method_name
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# The prefix for any instance method defined by the ::command method.
|
48
|
+
def command_prefix
|
49
|
+
:_run_
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/lib/runner.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
require 'semver'
|
2
|
+
require 'dsl'
|
2
3
|
|
3
4
|
module XSemVer
|
4
5
|
|
5
6
|
# Contains the logic for performing SemVer operations from the command line.
|
6
7
|
class Runner
|
7
8
|
|
8
|
-
|
9
|
-
end
|
10
|
-
|
9
|
+
include XSemVer::DSL
|
11
10
|
|
12
11
|
# Run a semver command. Raise a CommandError if the command does not exist.
|
13
12
|
# Expects an array of commands, such as ARGV.
|
14
13
|
def initialize(*args)
|
15
14
|
@args = args
|
16
|
-
|
17
|
-
method = "run_#{command}"
|
18
|
-
raise CommandError, "invalid command #{command}" unless self.class.method_defined?(method)
|
19
|
-
send method
|
15
|
+
run_command(@args.shift || :tag)
|
20
16
|
end
|
21
17
|
|
18
|
+
private
|
22
19
|
|
23
|
-
|
24
|
-
|
20
|
+
def next_param_or_error(error_message)
|
21
|
+
@args.shift || raise(CommandError, error_message)
|
22
|
+
end
|
23
|
+
|
24
|
+
def help_text
|
25
25
|
<<-HELP
|
26
26
|
semver commands
|
27
27
|
---------------
|
@@ -40,8 +40,10 @@ PLEASE READ http://semver.org
|
|
40
40
|
end
|
41
41
|
|
42
42
|
|
43
|
+
|
44
|
+
|
43
45
|
# Create a new .semver file if the file does not exist.
|
44
|
-
|
46
|
+
command :initialize, :init do
|
45
47
|
file = SemVer.file_name
|
46
48
|
if File.exist? file
|
47
49
|
puts "#{file} already exists"
|
@@ -50,13 +52,12 @@ PLEASE READ http://semver.org
|
|
50
52
|
version.save file
|
51
53
|
end
|
52
54
|
end
|
53
|
-
alias :run_init :run_initialize
|
54
55
|
|
55
56
|
|
56
57
|
# Increment the major, minor, or patch of the .semver file.
|
57
|
-
|
58
|
+
command :increment, :inc do
|
58
59
|
version = SemVer.find
|
59
|
-
dimension =
|
60
|
+
dimension = next_param_or_error("required: major | minor | patch")
|
60
61
|
case dimension
|
61
62
|
when 'major'
|
62
63
|
version.major += 1
|
@@ -74,54 +75,48 @@ PLEASE READ http://semver.org
|
|
74
75
|
version.metadata = ''
|
75
76
|
version.save
|
76
77
|
end
|
77
|
-
alias :run_inc :run_increment
|
78
78
|
|
79
79
|
|
80
80
|
# Set the pre-release of the .semver file.
|
81
|
-
|
81
|
+
command :special, :spe, :prerelease, :pre do
|
82
82
|
version = SemVer.find
|
83
|
-
|
84
|
-
version.special = special_str
|
83
|
+
version.special = next_param_or_error("required: an arbitrary string (beta, alfa, romeo, etc)")
|
85
84
|
version.save
|
86
85
|
end
|
87
|
-
alias :run_spe :run_special
|
88
|
-
alias :run_pre :run_special
|
89
|
-
alias :run_prerelease :run_special
|
90
86
|
|
91
87
|
|
92
88
|
# Set the metadata of the .semver file.
|
93
|
-
|
89
|
+
command :metadata, :meta do
|
94
90
|
version = SemVer.find
|
95
|
-
|
96
|
-
version.metadata = special_str
|
91
|
+
version.metadata = next_param_or_error("required: an arbitrary string (beta, alfa, romeo, etc)")
|
97
92
|
version.save
|
98
93
|
end
|
99
|
-
alias :run_meta :run_metadata
|
100
94
|
|
101
95
|
|
102
96
|
# Output the semver as specified by a format string.
|
103
97
|
# See: SemVer#format
|
104
|
-
|
98
|
+
command :format do
|
105
99
|
version = SemVer.find
|
106
|
-
|
107
|
-
puts version.format(format_str)
|
100
|
+
puts version.format(next_param_or_error("required: format string"))
|
108
101
|
end
|
109
102
|
|
110
103
|
|
111
104
|
# Output the semver with the default formatting.
|
112
105
|
# See: SemVer#to_s
|
113
|
-
|
106
|
+
command :tag do
|
114
107
|
version = SemVer.find
|
115
108
|
puts version.to_s
|
116
109
|
end
|
117
110
|
|
118
111
|
|
119
112
|
# Output instructions for using the semvar command.
|
120
|
-
|
121
|
-
puts
|
113
|
+
command :help do
|
114
|
+
puts help_text
|
122
115
|
end
|
123
116
|
|
124
|
-
|
117
|
+
|
118
|
+
|
119
|
+
|
125
120
|
end
|
126
121
|
|
127
122
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semver2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-12-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rspec
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- .semver
|
40
40
|
- semver2.gemspec
|
41
41
|
- README.md
|
42
|
+
- lib/dsl.rb
|
42
43
|
- lib/pre_release.rb
|
43
44
|
- lib/runner.rb
|
44
45
|
- lib/semver/semvermissingerror.rb
|
@@ -65,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
66
|
version: '0'
|
66
67
|
requirements: []
|
67
68
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.8.
|
69
|
+
rubygems_version: 1.8.23
|
69
70
|
signing_key:
|
70
71
|
specification_version: 3
|
71
72
|
summary: Semantic Versioning
|