Class: Sprout::VersionFile

Inherits:
Object
  • Object
show all
Defined in:
lib/sprout/version_file.rb

Overview

Used by the GitTask to load, parse and persist Version information related to a project. Expects a file with a 3 digit number, separated by periods like:

3.4.2

Create with a path to the file like:

version = VersionFile.new('path/Version.txt')

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ VersionFile

Returns a new instance of VersionFile.



15
16
17
18
# File 'lib/sprout/version_file.rb', line 15

def initialize(file_path)
  @file_path = file_path
  read_value
end

Instance Method Details

#increment_revisionObject



41
42
43
# File 'lib/sprout/version_file.rb', line 41

def increment_revision
  self.revision = self.revision + 1
end

#major_versionObject



29
30
31
# File 'lib/sprout/version_file.rb', line 29

def major_version
  @value.split('.').shift.to_i
end

#minor_versionObject



33
34
35
# File 'lib/sprout/version_file.rb', line 33

def minor_version
  @value.split('.')[1].to_i
end

#revisionObject



37
38
39
# File 'lib/sprout/version_file.rb', line 37

def revision
  @value.split('.').pop.to_i
end

#to_sObject



45
46
47
# File 'lib/sprout/version_file.rb', line 45

def to_s
  @value
end

#to_strObject



49
50
51
# File 'lib/sprout/version_file.rb', line 49

def to_str
  @value
end

#to_tagObject



53
54
55
56
57
58
59
# File 'lib/sprout/version_file.rb', line 53

def to_tag
  parts = value.split('.')
  parts[0] = add_leading_zeros(parts[0], 2)
  parts[1] = add_leading_zeros(parts[1], 2)
  parts[2] = add_leading_zeros(parts[2], 3)
  return parts.join('.')
end

#valueObject



25
26
27
# File 'lib/sprout/version_file.rb', line 25

def value
  @value
end

#value=(value) ⇒ Object



20
21
22
23
# File 'lib/sprout/version_file.rb', line 20

def value=(value)
  @value = value
  write_value
end