Class: Shaf::Upgrade::Version

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/shaf/upgrade/version.rb

Defined Under Namespace

Classes: UpgradeVersionError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Version

Returns a new instance of Version.



16
17
18
19
20
21
22
23
24
25
# File 'lib/shaf/upgrade/version.rb', line 16

def initialize(version)
  case version
  when Version
    @major, @minor, @patch = version.to_a
  when /\d+\.\d+(\.\d+)?/
    @major, @minor, @patch = split_version(version)
  else
    raise UpgradeVersionError, version
  end
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



6
7
8
# File 'lib/shaf/upgrade/version.rb', line 6

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



6
7
8
# File 'lib/shaf/upgrade/version.rb', line 6

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



6
7
8
# File 'lib/shaf/upgrade/version.rb', line 6

def patch
  @patch
end

Instance Method Details

#<=>(other) ⇒ Object



27
28
29
30
31
# File 'lib/shaf/upgrade/version.rb', line 27

def <=>(other)
  return unless other
  other = self.class.new(other)
  compare_version(other.major, other.minor, other.patch)
end

#to_aObject



37
38
39
# File 'lib/shaf/upgrade/version.rb', line 37

def to_a
  [major, minor, patch]
end

#to_sObject



33
34
35
# File 'lib/shaf/upgrade/version.rb', line 33

def to_s
  to_a.join('.')
end