Class: MacAdmin::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/macadmin/version.rb

Overview

Version

  • Class for working with the version number

Constant Summary collapse

FILE =
File.expand_path('version.yaml')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#majorObject

Returns the value of attribute major.



11
12
13
# File 'lib/macadmin/version.rb', line 11

def major
  @major
end

#minorObject

Returns the value of attribute minor.



11
12
13
# File 'lib/macadmin/version.rb', line 11

def minor
  @minor
end

#patchObject

Returns the value of attribute patch.



11
12
13
# File 'lib/macadmin/version.rb', line 11

def patch
  @patch
end

Class Method Details

.init_with_string(version) ⇒ Object

Create from String

  • ie. “0.0.1”



15
16
17
# File 'lib/macadmin/version.rb', line 15

def self.init_with_string(version)
  @major, @minor, @patch = version.split(".").each(&:to_i)
end

.load_yaml_file(file = FILE) ⇒ Object

Init from a YAML file



20
21
22
# File 'lib/macadmin/version.rb', line 20

def self.load_yaml_file(file = FILE)
  YAML.load_file FILE
end

Instance Method Details

#bump_majorObject

Increment the major version number



30
31
32
# File 'lib/macadmin/version.rb', line 30

def bump_major
  @major += 1
end

#bump_minorObject

Increment the minor version number



35
36
37
# File 'lib/macadmin/version.rb', line 35

def bump_minor
  @minor += 1
end

#bump_patchObject

Increment the patch version number



40
41
42
# File 'lib/macadmin/version.rb', line 40

def bump_patch
  @patch += 1
end

#save(file = FILE) ⇒ Object

Serialize the object to YAML file



45
46
47
# File 'lib/macadmin/version.rb', line 45

def save(file = FILE)
  File.open(file, 'w') { |f| f.write self.to_yaml }
end

#to_sObject

Returns a version String



25
26
27
# File 'lib/macadmin/version.rb', line 25

def to_s
  "#{@major}.#{@minor}.#{@patch}"
end