Class: Versionaire::Version
- Inherits:
-
Data
- Object
- Data
- Versionaire::Version
- Includes:
- Comparable
- Defined in:
- lib/versionaire/version.rb
Overview
An immutable, semantic version value object.
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #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.
12 13 14 15 |
# File 'lib/versionaire/version.rb', line 12 def initialize major: 0, minor: 0, patch: 0 super validate end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major
7 8 9 |
# File 'lib/versionaire/version.rb', line 7 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor
7 8 9 |
# File 'lib/versionaire/version.rb', line 7 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch
7 8 9 |
# File 'lib/versionaire/version.rb', line 7 def patch @patch end |
Instance Method Details
#+(other) ⇒ Object
17 |
# File 'lib/versionaire/version.rb', line 17 def +(other) = add other |
#-(other) ⇒ Object
19 |
# File 'lib/versionaire/version.rb', line 19 def -(other) = substract other |
#<=>(other) ⇒ Object
25 |
# File 'lib/versionaire/version.rb', line 25 def <=>(other) = to_s <=> other.to_s |
#==(other) ⇒ Object Also known as: eql?
21 |
# File 'lib/versionaire/version.rb', line 21 def ==(other) = hash == other.hash |
#bump(key) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/versionaire/version.rb', line 31 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
27 |
# File 'lib/versionaire/version.rb', line 27 def down(key, value = 1) = substract({key => value}) |
#inspect ⇒ Object
40 |
# File 'lib/versionaire/version.rb', line 40 def inspect = to_s.inspect |
#to_proc ⇒ Object
42 |
# File 'lib/versionaire/version.rb', line 42 def to_proc = method(:public_send).to_proc |
#to_s ⇒ Object Also known as: to_str
44 |
# File 'lib/versionaire/version.rb', line 44 def to_s = to_a.join DELIMITER |
#up(key, value = 1) ⇒ Object
29 |
# File 'lib/versionaire/version.rb', line 29 def up(key, value = 1) = add({key => value}) |