versionaire 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b35b90792f1bc9448598be77438f533e87a7ad04
4
- data.tar.gz: a07469a9bd80e8ba46578d69c028329c31fcc6a9
3
+ metadata.gz: 34468329f30afcc69ad0decfe31ef293346aa16f
4
+ data.tar.gz: 34a6064108cc26f6d5ee3b69653962911addf75b
5
5
  SHA512:
6
- metadata.gz: 2c0da5f8dae0567e5d40529c44d351dc2fd3361553187ff46e1441436679fe7cbf53b12c9a4624a3e79df571c5675ac28529589cdd29c8e6fde6b32653b8813e
7
- data.tar.gz: 30235a347bdd70d65553ea29f6da8a9016fde40741497574b896562eadd180739669289d631aa2218764b65b136cb5dcc381d98e8517cc58dd4998c148981d7d
6
+ metadata.gz: 42567538dadd2d31ab0013bde14b6abfd58dba8617fd5c45df909c1f56fc625b1a4d6a61d4a933fc21dbae2b34bc282ba0326740f880b85839424b5f322fa193
7
+ data.tar.gz: 8f52ad15a86d56ea3df8bdddb12d6041f8eb9b697218d3b0ff6f78190870a18a1bffc12aa051589e02c4367b4928f65db10ddd8f78c416e3c6ef7b3690aab0d8
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Travis CI Status](https://secure.travis-ci.org/bkuhlmann/versionaire.svg)](https://travis-ci.org/bkuhlmann/versionaire)
8
8
  [![Patreon](https://img.shields.io/badge/patreon-donate-brightgreen.svg)](https://www.patreon.com/bkuhlmann)
9
9
 
10
- Provides immutable, semantic versioning.
10
+ Provides immutable, thread-safe, semantic versioning.
11
11
 
12
12
  <!-- Tocer[start]: Auto-generated, don't remove. -->
13
13
 
@@ -18,16 +18,19 @@ Provides immutable, semantic versioning.
18
18
  - [Requirements](#requirements)
19
19
  - [Setup](#setup)
20
20
  - [Usage](#usage)
21
- - [Basic](#basic)
22
- - [Math](#math)
23
- - [Add](#add)
24
- - [Subtract](#subtract)
25
- - [Comparisons](#comparisons)
21
+ - [Initialization](#initialization)
26
22
  - [Equality](#equality)
27
- - [Identity](#identity)
28
- - [Implicit Conversions](#implicit-conversions)
29
- - [Explicit Conversions](#explicit-conversions)
30
- - [Conversions (Casting)](#conversions-casting)
23
+ - [Value (`#==`)](#value-)
24
+ - [Hash (`#eql?`)](#hash-eql)
25
+ - [Case (`#===`)](#case-)
26
+ - [Identity (`#equal?`)](#identity-equal)
27
+ - [Conversions](#conversions)
28
+ - [Function (Casting)](#function-casting)
29
+ - [Implicit](#implicit)
30
+ - [Explicit](#explicit)
31
+ - [Math](#math)
32
+ - [Addition](#addition)
33
+ - [Subtraction](#subtraction)
31
34
  - [Tests](#tests)
32
35
  - [Versioning](#versioning)
33
36
  - [Code of Conduct](#code-of-conduct)
@@ -41,14 +44,12 @@ Provides immutable, semantic versioning.
41
44
  # Features
42
45
 
43
46
  - Provides [Semantic Versioning](http://semver.org).
44
- - Provides immutable version instances.
45
- - Provides conversions (casts) from a `String`, `Array`, `Hash`, or `Version` to a new `Version`.
46
- - Provides impicit conversion to a `String`.
47
- - Provides explicit conversions to a `String`, `Array`, and a `Hash`.
47
+ - Provides immutable, thread-safe version instances.
48
+ - Provides conversions (casts) from a `String`, `Array`, `Hash`, or `Version` to a `Version`.
48
49
 
49
50
  # Screencasts
50
51
 
51
- TBD
52
+ [![asciicast](https://asciinema.org/a/26561.png)](https://asciinema.org/a/40455)
52
53
 
53
54
  # Requirements
54
55
 
@@ -74,7 +75,7 @@ Add the following to your Gemfile:
74
75
 
75
76
  # Usage
76
77
 
77
- ## Basic
78
+ ## Initialization
78
79
 
79
80
  A new version can be initialized in a variety of ways:
80
81
 
@@ -83,80 +84,72 @@ A new version can be initialized in a variety of ways:
83
84
  Versionaire::Version.new major: 1, minor: 2 # "1.2.0"
84
85
  Versionaire::Version.new major: 1, minor: 2, maintenance: 3 # "1.2.3"
85
86
 
86
- ## Math
87
+ ## Equality
87
88
 
88
- Versions can be added and subtracted from each other.
89
+ ### Value (`#==`)
89
90
 
90
- ### Add
91
+ Equality is deterimined by the state of the object. This means that a version is equal to another version as long as
92
+ all of the values (i.e. state) are equal to each other. Example:
91
93
 
92
- version_1 = Versionaire::Version.new major: 1, minor: 2, maintenance: 3
93
- version_2 = Versionaire::Version.new major: 2, minor: 5, maintenance: 7
94
- version_1 + version_2 # "3.7.10"
94
+ version_a = Versionaire::Version.new major: 1
95
+ version_b = Versionaire::Version.new major: 2
96
+ version_c = Versionaire::Version.new major: 1
95
97
 
96
- ### Subtract
98
+ version_a == version_a # true
99
+ version_a == version_b # false
100
+ version_a == version_c # true
97
101
 
98
- version_1 = Versionaire::Version.new major: 1, minor: 2, maintenance: 3
99
- version_2 = Versionaire::Version.new major: 1, minor: 1, maintenance: 1
100
- version_1 - version_2 # "0.1.2"
102
+ Knowning this, versions can be compared against one another too:
101
103
 
102
- version_1 = Versionaire::Version.new major: 1
103
- version_2 = Versionaire::Version.new major: 5
104
- version_1 - version_2 # Fails with a Versionaire::Errors::NegativeNumber
104
+ version_a > version_b # false
105
+ version_a < version_b # true
106
+ version_a.between? version_c, version_b # true
105
107
 
106
- ## Comparisons
108
+ ### Hash (`#eql?`)
107
109
 
108
- Versions can be compared against other versions:
110
+ Behaves exactly as `#==`.
109
111
 
110
- version_1 = Versionaire::Version.new major: 1
111
- version_2 = Versionaire::Version.new major: 5
112
+ ### Case (`#===`)
112
113
 
113
- version_1 > version_2 # false
114
- version_1 == version_2 # false
115
- version_1 < version_2 # true
114
+ Behaves exactly as `#==`.
116
115
 
117
- Versions can't be compared to similar objects:
116
+ ### Identity (`#equal?`)
118
117
 
119
- version = Versionaire::Version.new major: 1
118
+ Works like any other standard Ruby object where an object is equal only to itself.
120
119
 
121
- version == "1.0.0" # false
122
- version == [1, 0, 0] # false
123
- version == {major: 1, minor: 0, maintenance: 0} # false
120
+ version_a = Versionaire::Version.new major: 1
121
+ version_b = Versionaire::Version.new major: 2
122
+ version_c = Versionaire::Version.new major: 1
124
123
 
125
- ## Equality
124
+ version_a.equal? version_a # true
125
+ version_a.equal? version_b # false
126
+ version_a.equal? version_c # false
126
127
 
127
- Equality is based on the values that make up the version, not identity.
128
+ ## Conversions
128
129
 
129
- version = Versionaire::Version.new major: 1, minor: 2, maintenance: 3
130
- identical = Versionaire::Version.new major: 1, minor: 2, maintenance: 3
131
- different = Versionaire::Version.new major: 3
130
+ ### Function (Casting)
132
131
 
133
- version == version # true
134
- version == identical # true
135
- version == different # false
132
+ The `Versionaire::Version` function is provided for explicit casting to a version:
136
133
 
137
- This is the same behavior for `#eql?` method too.
138
-
139
- ## Identity
140
-
141
- Identity is composed of the values that make up the version plus the class:
134
+ version = Versionaire::Version.new major: 1
142
135
 
143
- version = Versionaire::Version.new major: 1, minor: 2, maintenance: 3
144
- identical = Versionaire::Version.new major: 1, minor: 2, maintenance: 3
145
- different = Versionaire::Version.new major: 3
136
+ Versionaire::Version "1.0.0"
137
+ Versionaire::Version [1, 0, 0]
138
+ Versionaire::Version major: 1, minor: 0, maintenance: 0
139
+ Versionaire::Version version
146
140
 
147
- version.hash # -4162833121614102126
148
- identical.hash # -4162833121614102126
149
- different.hash # -2082793513660996236
141
+ Each of these conversions will result in a version object that represents "1.0.0". When attempting to convert an
142
+ unsupported type, a `Versionaire::Errors::Conversion` exception will be thrown.
150
143
 
151
- ## Implicit Conversions
144
+ ### Implicit
152
145
 
153
146
  Implicit conversion to a `String` is supported:
154
147
 
155
148
  "1.0.0".match Versionaire::Version.new(major: 1) # <MatchData "1.0.0">
156
149
 
157
- ## Explicit Conversions
150
+ ### Explicit
158
151
 
159
- Explicit converting to a `String`, `Array`, or `Hash` is supported:
152
+ Explicit conversion to a `String`, `Array`, or `Hash` is supported:
160
153
 
161
154
  version = Versionaire::Version.new
162
155
 
@@ -164,19 +157,25 @@ Explicit converting to a `String`, `Array`, or `Hash` is supported:
164
157
  version.to_a # [0, 0, 0]
165
158
  version.to_h # {major: 0, minor: 0, maintenance: 0}
166
159
 
167
- ## Conversions (Casting)
160
+ ## Math
168
161
 
169
- The `Versionaire::Version` function is provided for explicit conversion (casting) to a new version:
162
+ Versions can be added and subtracted from each other.
170
163
 
171
- version = Versionaire::Version.new major: 1
164
+ ### Addition
172
165
 
173
- Versionaire::Version "1.0.0"
174
- Versionaire::Version [1, 0, 0]
175
- Versionaire::Version major: 1, minor: 0, maintenance: 0
176
- Versionaire::Version version
166
+ version_1 = Versionaire::Version.new major: 1, minor: 2, maintenance: 3
167
+ version_2 = Versionaire::Version.new major: 2, minor: 5, maintenance: 7
168
+ version_1 + version_2 # "3.7.10"
177
169
 
178
- Each of these conversions will result in a new version object that is equal to "1.0.0". When attempting to convert an
179
- unsupported type, a `Versionaire::Errors::Conversion` exception will be thrown.
170
+ ### Subtraction
171
+
172
+ version_1 = Versionaire::Version.new major: 1, minor: 2, maintenance: 3
173
+ version_2 = Versionaire::Version.new major: 1, minor: 1, maintenance: 1
174
+ version_1 - version_2 # "0.1.2"
175
+
176
+ version_1 = Versionaire::Version.new major: 1
177
+ version_2 = Versionaire::Version.new major: 5
178
+ version_1 - version_2 # Fails with a Versionaire::Errors::NegativeNumber
180
179
 
181
180
  # Tests
182
181
 
@@ -2,27 +2,57 @@
2
2
 
3
3
  # The gem namespace.
4
4
  module Versionaire
5
- # Conversion function for casting (strict) a value into a version.
5
+ # Conversion function (strict) for casting an object into a version.
6
6
  # rubocop:disable Style/MethodName
7
- # rubocop:disable Metrics/MethodLength
8
- # rubocop:disable Metrics/AbcSize
9
- # rubocop:disable Metrics/CyclomaticComplexity
10
- def Version value
11
- case value
12
- when String
13
- fail(Errors::Conversion, Errors::Conversion.string_message) unless value =~ Version.format
14
- Version.new Version.arguments(*value.tr("v", "").split(".").map(&:to_i))
15
- when Array
16
- fail(Errors::Conversion, Errors::Conversion.array_message) unless (0..3).cover?(value.size)
17
- Version.new Version.arguments(*value.fill(0, value.size..2))
18
- when Hash
19
- valid = value.keys.all? { |key| Version.keys.include? key }
20
- fail(Errors::Conversion, Errors::Conversion.hash_message) unless valid
21
- Version.new value
22
- when Version then value
23
- else fail(Errors::Conversion, Errors::Conversion.primitive_message)
7
+ def Version object
8
+ aid = VersionAid.new object
9
+
10
+ case object
11
+ when String then aid.convert_from_string
12
+ when Array then aid.convert_from_array
13
+ when Hash then aid.convert_from_hash
14
+ when Version then object
15
+ else fail Errors::Conversion, Errors::Conversion.primitive_message
24
16
  end
25
17
  end
26
-
27
18
  module_function :Version
19
+
20
+ # Aids with converting objects into valid versions.
21
+ class VersionAid
22
+ def initialize value
23
+ @value = value
24
+ end
25
+
26
+ def convert_from_string
27
+ fail(Errors::Conversion, Errors::Conversion.string_message) unless value =~ Version.string_format
28
+ Version.new string_to_arguments
29
+ end
30
+
31
+ def convert_from_array
32
+ fail(Errors::Conversion, Errors::Conversion.array_message) unless (0..3).cover?(value.size)
33
+ Version.new array_to_arguments
34
+ end
35
+
36
+ def convert_from_hash
37
+ fail(Errors::Conversion, Errors::Conversion.hash_message) unless required_keys?
38
+ Version.new value
39
+ end
40
+
41
+ private
42
+
43
+ attr_reader :value
44
+
45
+ def string_to_arguments
46
+ Version.arguments(*value.tr("v", "").split(".").map(&:to_i))
47
+ end
48
+
49
+ def array_to_arguments
50
+ Version.arguments(*value.fill(0, value.size..2))
51
+ end
52
+
53
+ def required_keys?
54
+ value.keys.all? { |key| Version.keys.include? key }
55
+ end
56
+ end
57
+ private_constant :VersionAid
28
58
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Versionaire
2
4
  module Errors
3
5
  # The base error class for all gem-related errors.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Versionaire
2
4
  module Errors
3
5
  # Thrown when attempting to convert (cast) a primitive to a version.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Versionaire
2
4
  module Errors
3
5
  # Thrown when not using numbers.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Versionaire
2
4
  module Errors
3
5
  # Thrown when numbers are negative.
@@ -12,7 +12,7 @@ module Versionaire
12
12
  end
13
13
 
14
14
  def self.version
15
- "0.1.0"
15
+ "1.0.0"
16
16
  end
17
17
 
18
18
  def self.version_label
@@ -11,8 +11,17 @@ module Versionaire
11
11
  %i(major minor maintenance)
12
12
  end
13
13
 
14
- def self.format
15
- /\Av?\d{1,}\.\d{1,}\.\d{1,}\z/
14
+ def self.string_format
15
+ /
16
+ \A # Start of string.
17
+ v? # Optional prefix.
18
+ \d{1,} # Major version.
19
+ \. # Delimiter.
20
+ \d{1,} # Minor version.
21
+ \. # Delimiter.
22
+ \d{1,} # Maintenance version.
23
+ \z # End of string.
24
+ /x
16
25
  end
17
26
 
18
27
  def self.arguments major, minor, maintenance
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: versionaire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -30,7 +30,7 @@ cert_chain:
30
30
  aSif+qBc6oHD7EQWPF5cZkzkIURuwNwPBngZGxIKaMAgRhjGFXzUMAaq++r59cS9
31
31
  xTfQ4k6fglKEgpnLAXiKdo2c8Ym+X4rIKFfedQ==
32
32
  -----END CERTIFICATE-----
33
- date: 2016-03-19 00:00:00.000000000 Z
33
+ date: 2016-03-26 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: bundler
@@ -158,6 +158,62 @@ dependencies:
158
158
  - - ">="
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
+ - !ruby/object:Gem::Dependency
162
+ name: bond
163
+ requirement: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ type: :development
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ - !ruby/object:Gem::Dependency
176
+ name: wirb
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ - !ruby/object:Gem::Dependency
190
+ name: hirb
191
+ requirement: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ type: :development
197
+ prerelease: false
198
+ version_requirements: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ - !ruby/object:Gem::Dependency
204
+ name: awesome_print
205
+ requirement: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ type: :development
211
+ prerelease: false
212
+ version_requirements: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
161
217
  - !ruby/object:Gem::Dependency
162
218
  name: rspec
163
219
  requirement: !ruby/object:Gem::Requirement
@@ -256,7 +312,7 @@ dependencies:
256
312
  - - ">="
257
313
  - !ruby/object:Gem::Version
258
314
  version: '0'
259
- description: Provides immutable, semantic versioning.
315
+ description: Provides immutable, thread-safe, semantic versioning.
260
316
  email:
261
317
  - brooke@alchemists.io
262
318
  executables: []
@@ -288,9 +344,9 @@ require_paths:
288
344
  - lib
289
345
  required_ruby_version: !ruby/object:Gem::Requirement
290
346
  requirements:
291
- - - ">="
347
+ - - "~>"
292
348
  - !ruby/object:Gem::Version
293
- version: '0'
349
+ version: '2.3'
294
350
  required_rubygems_version: !ruby/object:Gem::Requirement
295
351
  requirements:
296
352
  - - ">="
@@ -301,5 +357,5 @@ rubyforge_project:
301
357
  rubygems_version: 2.6.2
302
358
  signing_key:
303
359
  specification_version: 4
304
- summary: Provides immutable, semantic versioning.
360
+ summary: Provides immutable, thread-safe, semantic versioning.
305
361
  test_files: []
metadata.gz.sig CHANGED
Binary file