Class: Versionaire::Version
- Inherits:
-
Struct
- Object
- Struct
- Versionaire::Version
- Includes:
- Comparable
- Defined in:
- lib/versionaire/version.rb
Overview
An immutable, semantic version value object.
Instance Attribute Summary collapse
-
#major ⇒ Object
Returns the value of attribute major.
-
#minor ⇒ Object
Returns the value of attribute minor.
-
#patch ⇒ Object
Returns the value of attribute patch.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #[]=(key, value) ⇒ Object
- #bump(key) ⇒ Object
- #down(key, value = 1) ⇒ Object
-
#initialize(major: 0, minor: 0, patch: 0) ⇒ Version
constructor
A new instance of Version.
- #inspect ⇒ Object
- #to_proc ⇒ Object
- #to_s ⇒ Object (also: #to_str)
- #up(key, value = 1) ⇒ Object
Constructor Details
#initialize(major: 0, minor: 0, patch: 0) ⇒ Version
Returns a new instance of Version.
14 15 16 17 18 |
# File 'lib/versionaire/version.rb', line 14 def initialize major: 0, minor: 0, patch: 0 super validate freeze end |
Instance Attribute Details
#major ⇒ Object
Returns the value of attribute major
8 9 10 |
# File 'lib/versionaire/version.rb', line 8 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor
8 9 10 |
# File 'lib/versionaire/version.rb', line 8 def minor @minor end |
#patch ⇒ Object
Returns the value of attribute patch
8 9 10 |
# File 'lib/versionaire/version.rb', line 8 def patch @patch end |
Instance Method Details
#+(other) ⇒ Object
24 |
# File 'lib/versionaire/version.rb', line 24 def +(other) = (revalue(other.to_h) { |previous, current| previous + current }).freeze |
#-(other) ⇒ Object
26 |
# File 'lib/versionaire/version.rb', line 26 def -(other) = (revalue(other.to_h) { |previous, current| previous - current }).freeze |
#<=>(other) ⇒ Object
32 |
# File 'lib/versionaire/version.rb', line 32 def <=>(other) = to_s <=> other.to_s |
#==(other) ⇒ Object Also known as: eql?
28 |
# File 'lib/versionaire/version.rb', line 28 def ==(other) = hash == other.hash |
#[]=(key, value) ⇒ Object
20 21 22 |
# File 'lib/versionaire/version.rb', line 20 def []= key, value super.tap { validate } end |
#bump(key) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/versionaire/version.rb', line 42 def bump key case key when :major then bump_major when :minor then bump_minor when :patch then bump_patch else fail Error, %(Invalid key: #{key.inspect}. Use: #{members.to_sentence "or"}.) end end |
#down(key, value = 1) ⇒ Object
34 35 36 |
# File 'lib/versionaire/version.rb', line 34 def down key, value = 1 (revalue(key => value) { |previous, current| previous - current }).freeze end |
#inspect ⇒ Object
51 |
# File 'lib/versionaire/version.rb', line 51 def inspect = to_s.inspect |
#to_proc ⇒ Object
53 |
# File 'lib/versionaire/version.rb', line 53 def to_proc = method(:[]).to_proc |
#to_s ⇒ Object Also known as: to_str
55 |
# File 'lib/versionaire/version.rb', line 55 def to_s = to_a.join DELIMITER |
#up(key, value = 1) ⇒ Object
38 39 40 |
# File 'lib/versionaire/version.rb', line 38 def up key, value = 1 (revalue(key => value) { |previous, current| previous + current }).freeze end |