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]+))?/
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.
-
#update(segment) ⇒ String
Updates the specified segment of the version string.
- #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.
81 82 83 |
# File 'lib/reissue/version_updater.rb', line 81 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.
84 85 86 87 88 89 90 |
# File 'lib/reissue/version_updater.rb', line 84 def redo(version, segment) if version_redo_proc version_redo_proc.call(version, segment) else version.redo(segment) end end |
#update(segment) ⇒ String
Updates the specified segment of the version string.
96 97 98 99 100 101 102 103 |
# File 'lib/reissue/version_updater.rb', line 96 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 |
#version_regex ⇒ Object
109 |
# File 'lib/reissue/version_updater.rb', line 109 def version_regex = VERSION_MATCH |
#write(version_file = @version_file) ⇒ Object
Writes the updated version to the specified file.
114 115 116 |
# File 'lib/reissue/version_updater.rb', line 114 def write(version_file = @version_file) File.write(version_file, @updated_body) end |