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
- #dev_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
106 107 108 |
# File 'lib/mark_version/version_file.rb', line 106 def current_major_version version_as_array[0] end |
#current_minor_version ⇒ Object
102 103 104 |
# File 'lib/mark_version/version_file.rb', line 102 def current_minor_version version_as_array[1] end |
#current_patch_version ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/mark_version/version_file.rb', line 94 def current_patch_version if version.include?('RC') version_as_array[2].split('-')[0] else version_as_array[2] end end |
#dev_version ⇒ Object
32 33 34 35 36 37 |
# File 'lib/mark_version/version_file.rb', line 32 def dev_version return "#{version}.#{Git.branch}+#{Git.ahead_of_release_by}" unless Git.on_release_branch? return "#{version}+#{Git.current_ahead_by}" if Git.current_ahead_of_version? version end |
#file_exists? ⇒ Boolean
18 19 20 |
# File 'lib/mark_version/version_file.rb', line 18 def file_exists? File.file?(file_name) end |
#increment_release_candidate ⇒ Object
84 85 86 87 |
# File 'lib/mark_version/version_file.rb', line 84 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 |
# 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.rewind @version_file.close version end |
#major ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/mark_version/version_file.rb', line 62 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
78 79 80 81 82 |
# File 'lib/mark_version/version_file.rb', line 78 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
53 54 55 56 57 58 59 60 |
# File 'lib/mark_version/version_file.rb', line 53 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
72 73 74 75 76 |
# File 'lib/mark_version/version_file.rb', line 72 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
45 46 47 48 49 50 51 |
# File 'lib/mark_version/version_file.rb', line 45 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
89 90 91 92 |
# File 'lib/mark_version/version_file.rb', line 89 def release fail 'Cannot release a non release candidate.' unless release_candidate? write(short_version) end |
#release_candidate? ⇒ Boolean
114 115 116 |
# File 'lib/mark_version/version_file.rb', line 114 def release_candidate? version.include?('RC') end |
#release_candidate_iteration ⇒ Object
110 111 112 |
# File 'lib/mark_version/version_file.rb', line 110 def release_candidate_iteration version.split('RC')[1].to_s end |
#short_version ⇒ Object
39 40 41 42 43 |
# File 'lib/mark_version/version_file.rb', line 39 def short_version return version unless release_candidate? version.split('-')[0] end |
#version ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/mark_version/version_file.rb', line 22 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 |