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

#kindObject



42
43
44
45
46
47
48
# File 'lib/versionaire/version.rb', line 42

def kind
  if major? then :major
  elsif minor? then :minor
  elsif patch? then :patch
  else :nascent
  end
end

#major?Boolean

Returns:

  • (Boolean)


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

def major? = major.positive? && minor.zero? && patch.zero?

#minor?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
# File 'lib/versionaire/version.rb', line 52

def minor?
  nonmajor = major.zero?
  nonpatch = patch.zero?

  !(nonmajor && minor.zero? && nonpatch) &&
    (nonmajor || major.positive?) && minor.positive? && nonpatch
end

#patch?Boolean

Returns:

  • (Boolean)


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

def patch? = patch.positive?

#to_procObject



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

def to_proc = method(:public_send).to_proc

#to_sObject Also known as: to_str



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

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