Class: Versionaire::Version

Inherits:
Data
  • Object
show all
Includes:
Comparable
Defined in:
lib/versionaire/version.rb

Overview

An immutable, semantic version value object.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#majorObject (readonly)

Returns the value of attribute major

Returns:

  • (Object)

    the current value of major



7
8
9
# File 'lib/versionaire/version.rb', line 7

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor

Returns:

  • (Object)

    the current value of minor



7
8
9
# File 'lib/versionaire/version.rb', line 7

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch

Returns:

  • (Object)

    the current value of 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})

#inspectObject



40
# File 'lib/versionaire/version.rb', line 40

def inspect = to_s.inspect

#to_procObject



42
# File 'lib/versionaire/version.rb', line 42

def to_proc = method(:public_send).to_proc

#to_sObject 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})