Class: Sprout::VersionFile
- Inherits:
-
Object
- Object
- Sprout::VersionFile
- 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
- #increment_revision ⇒ Object
-
#initialize(file_path) ⇒ VersionFile
constructor
A new instance of VersionFile.
- #major_version ⇒ Object
- #minor_version ⇒ Object
- #revision ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
- #to_tag ⇒ Object
- #value ⇒ Object
- #value=(value) ⇒ Object
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_revision ⇒ Object
41 42 43 |
# File 'lib/sprout/version_file.rb', line 41 def increment_revision self.revision = self.revision + 1 end |
#major_version ⇒ Object
29 30 31 |
# File 'lib/sprout/version_file.rb', line 29 def major_version @value.split('.').shift.to_i end |
#minor_version ⇒ Object
33 34 35 |
# File 'lib/sprout/version_file.rb', line 33 def minor_version @value.split('.')[1].to_i end |
#revision ⇒ Object
37 38 39 |
# File 'lib/sprout/version_file.rb', line 37 def revision @value.split('.').pop.to_i end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/sprout/version_file.rb', line 45 def to_s @value end |
#to_str ⇒ Object
49 50 51 |
# File 'lib/sprout/version_file.rb', line 49 def to_str @value end |
#to_tag ⇒ Object
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 |
#value ⇒ Object
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 |