Class: VersionFile
- Inherits:
-
Object
- Object
- VersionFile
- Defined in:
- lib/mark_version/version_file.rb
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
Instance Method Summary collapse
- #current_major_version ⇒ Object
- #current_minor_version ⇒ Object
- #current_patch_version ⇒ Object
- #file_exists? ⇒ Boolean
- #increment_release_candidate ⇒ Object
- #init ⇒ Object
-
#initialize(file_name = 'VERSION') ⇒ VersionFile
constructor
A new instance of VersionFile.
- #major ⇒ Object
- #major_release_candidate ⇒ Object
- #minor ⇒ Object
- #minor_release_candidate ⇒ Object
- #patch ⇒ Object
- #release ⇒ Object
- #release_candidate? ⇒ Boolean
- #release_candidate_iteration ⇒ Object
- #short_version ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(file_name = 'VERSION') ⇒ VersionFile
Returns a new instance of VersionFile.
4 5 6 |
# File 'lib/mark_version/version_file.rb', line 4 def initialize(file_name = 'VERSION') @file_name = file_name end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
2 3 4 |
# File 'lib/mark_version/version_file.rb', line 2 def file_name @file_name end |
Instance Method Details
#current_major_version ⇒ Object
98 99 100 |
# File 'lib/mark_version/version_file.rb', line 98 def current_major_version version_as_array[0] end |
#current_minor_version ⇒ Object
94 95 96 |
# File 'lib/mark_version/version_file.rb', line 94 def current_minor_version version_as_array[1] end |
#current_patch_version ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/mark_version/version_file.rb', line 86 def current_patch_version if version.include?('RC') version_as_array[2].split('-')[0] else version_as_array[2] end end |
#file_exists? ⇒ Boolean
19 20 21 |
# File 'lib/mark_version/version_file.rb', line 19 def file_exists? File.file?(file_name) end |
#increment_release_candidate ⇒ Object
76 77 78 79 |
# File 'lib/mark_version/version_file.rb', line 76 def increment_release_candidate fail 'Cannot increment the release candidate version on a non release candidate.' unless release_candidate? write("#{short_version}-RC#{next_release_candidate}") end |
#init ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mark_version/version_file.rb', line 8 def init fail 'Project already initialized.' if file_exists? @version_file = open(file_name, 'w') @version_file.rewind @version_file.puts('0.0.0') @version_file.print(revision) @version_file.rewind @version_file.close version end |
#major ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/mark_version/version_file.rb', line 54 def major fail 'Cannot major increment a release candidate, it needs to be released first.' if release_candidate? version = version_as_array version[2] = '0' version[1] = '0' version[0] = (version[0].to_i + 1).to_s write(version.join('.')) end |
#major_release_candidate ⇒ Object
70 71 72 73 74 |
# File 'lib/mark_version/version_file.rb', line 70 def major_release_candidate fail 'Cannot make a releae candidate out of a release candidate. To increment to the next release candidate, invoke "increment_release_candidate".' if release_candidate? major write("#{version}-RC1") end |
#minor ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/mark_version/version_file.rb', line 45 def minor fail 'Cannot minor increment a release candidate, it needs to be released first.' if release_candidate? version = version_as_array version[2] = '0' version[1] = (version[1].to_i + 1).to_s write(version.join('.')) end |
#minor_release_candidate ⇒ Object
64 65 66 67 68 |
# File 'lib/mark_version/version_file.rb', line 64 def minor_release_candidate fail 'Cannot make a releae candidate out of a release candidate. To increment to the next release candidate, invoke "increment_release_candidate".' if release_candidate? minor write("#{short_version}-RC1") end |
#patch ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/mark_version/version_file.rb', line 37 def patch fail 'Cannot patch a release candidate, it needs to be released first.' if release_candidate? version = version_as_array version[2] = (version[2].to_i + 1).to_s write(version.join('.')) end |
#release ⇒ Object
81 82 83 84 |
# File 'lib/mark_version/version_file.rb', line 81 def release fail 'Cannot release a non release candidate.' unless release_candidate? write(short_version) end |
#release_candidate? ⇒ Boolean
106 107 108 |
# File 'lib/mark_version/version_file.rb', line 106 def release_candidate? version.include?('RC') end |
#release_candidate_iteration ⇒ Object
102 103 104 |
# File 'lib/mark_version/version_file.rb', line 102 def release_candidate_iteration version.split('RC')[1].to_s end |
#short_version ⇒ Object
31 32 33 34 35 |
# File 'lib/mark_version/version_file.rb', line 31 def short_version return version unless release_candidate? version.split('-')[0] end |
#version ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/mark_version/version_file.rb', line 23 def version fail "Version file '#{file_name}' does not exist." unless file_exists? @version_file = open(file_name, 'r+') version = @version_file.readline.chomp @version_file.close version end |