Class: Reissue::VersionUpdater
- Inherits:
-
Object
- Object
- Reissue::VersionUpdater
- Defined in:
- lib/reissue/version_updater.rb
Constant Summary collapse
- VERSION_MATCH =
Regular expression pattern for matching the version string.
/(?<major>\d+)\.(?<minor>[a-zA-Z\d]+)\.(?<patch>[a-zA-Z\d]+)(?<add>\.(?<pre>[a-zA-Z\d]+))?/- RELEASE_VERSION_MATCH =
/VERSION\s*=\s*"([^"]*)"/- RELEASE_DATE_MATCH =
/RELEASE_DATE\s*=\s*"([^"]*)"/
Instance Attribute Summary collapse
-
#version_redo_proc ⇒ Object
A proc that can be used to redo the version string.
Instance Method Summary collapse
-
#call(segment, version_file: @version_file) ⇒ String
Updates the version segment and writes the updated version to the file.
-
#initialize(version_file, version_redo_proc: nil) ⇒ VersionUpdater
constructor
Initializes a new instance of the VersionUpdater class.
-
#redo(version, segment) ⇒ Object
Creates a new version string based on the original version and the specified segment.
- #release_date_regex ⇒ Object
- #release_version_regex ⇒ Object
- #set_version(version_string, version_file: @version_file) ⇒ Object
-
#update(segment) ⇒ String
Updates the specified segment of the version string.
- #update_release_date(date, version_file: @version_file) ⇒ Object
- #version_regex ⇒ Object
-
#write(version_file = @version_file) ⇒ Object
Writes the updated version to the specified file.
Constructor Details
#initialize(version_file, version_redo_proc: nil) ⇒ VersionUpdater
Initializes a new instance of the VersionUpdater class.
59 60 61 62 63 64 65 |
# File 'lib/reissue/version_updater.rb', line 59 def initialize(version_file, version_redo_proc: nil) @version_file = version_file @original_version = nil @new_version = nil @updated_body = "" @version_redo_proc = version_redo_proc end |
Instance Attribute Details
#version_redo_proc ⇒ Object
A proc that can be used to redo the version string.
90 91 92 |
# File 'lib/reissue/version_updater.rb', line 90 def version_redo_proc @version_redo_proc end |
Instance Method Details
#call(segment, version_file: @version_file) ⇒ String
Updates the version segment and writes the updated version to the file.
This allows you to read from one file and write to another.
74 75 76 77 78 |
# File 'lib/reissue/version_updater.rb', line 74 def call(segment, version_file: @version_file) update(segment) write(version_file) @new_version end |
#redo(version, segment) ⇒ Object
Creates a new version string based on the original version and the specified segment.
93 94 95 96 97 98 99 |
# File 'lib/reissue/version_updater.rb', line 93 def redo(version, segment) if version_redo_proc version_redo_proc.call(version, segment) else version.redo(segment) end end |
#release_date_regex ⇒ Object
124 |
# File 'lib/reissue/version_updater.rb', line 124 def release_date_regex = RELEASE_DATE_MATCH |
#release_version_regex ⇒ Object
123 |
# File 'lib/reissue/version_updater.rb', line 123 def release_version_regex = RELEASE_VERSION_MATCH |
#set_version(version_string, version_file: @version_file) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/reissue/version_updater.rb', line 80 def set_version(version_string, version_file: @version_file) body = File.read(@version_file) updated = body.gsub(release_version_regex) do |match| match.sub(/=\s*"[^"]*"/, "= \"#{version_string}\"") end File.write(version_file, updated) version_string end |
#update(segment) ⇒ String
Updates the specified segment of the version string.
105 106 107 108 109 110 111 112 |
# File 'lib/reissue/version_updater.rb', line 105 def update(segment) version_file = File.read(@version_file) @updated_body = version_file.gsub(version_regex) do |string| @original_version = ::Gem::Version.new(string) @new_version = self.redo(::Gem::Version.new(string), segment).to_s end @new_version end |
#update_release_date(date, version_file: @version_file) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/reissue/version_updater.rb', line 126 def update_release_date(date, version_file: @version_file) body = File.read(@version_file) return unless body.match?(release_date_regex) updated = body.gsub(release_date_regex) do |match| match.sub(/=\s*"[^"]*"/, "= \"#{date}\"") end File.write(version_file, updated) end |
#version_regex ⇒ Object
118 |
# File 'lib/reissue/version_updater.rb', line 118 def version_regex = VERSION_MATCH |
#write(version_file = @version_file) ⇒ Object
Writes the updated version to the specified file.
138 139 140 |
# File 'lib/reissue/version_updater.rb', line 138 def write(version_file = @version_file) File.write(version_file, @updated_body) end |