From 66b610c4fae319f9ac96b9e4d04d3e97b7a72b80 Mon Sep 17 00:00:00 2001 From: Jim Gay <jim@saturnflyer.com> Date: Sat, 14 Sep 2024 17:30:38 -0400 Subject: [PATCH] Inject constants in the create method --- CHANGELOG.md | 1 + lib/reissue/rake.rb | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83f4a4b..14dc596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Set the name of the `reissue:branch` argument to `branch_name` to be clearer. +- Inject the constants in the `create` method. ## [0.3.0] - 2024-09-06 diff --git a/lib/reissue/rake.rb b/lib/reissue/rake.rb index ea77a4d..557fb04 100644 --- a/lib/reissue/rake.rb +++ b/lib/reissue/rake.rb @@ -60,8 +60,10 @@ def updated_paths # Set this to :branch to push to a new branch. attr_accessor :push_reissue - def initialize(name = :reissue) + def initialize(name = :reissue, formatter: Reissue, tasker: Rake::Task) @name = name + @formatter = formatter + @tasker = tasker @description = "Prepare the code for work on a new version." @version_file = nil @updated_paths = [] @@ -74,6 +76,9 @@ def initialize(name = :reissue) @push_reissue = :branch end + attr_reader :formatter, :tasker + private :formatter, :tasker + def finalize_with_branch? push_finalize == :branch end @@ -94,7 +99,7 @@ def define desc description task name, [:segment] do |task, args| segment = args[:segment] || "patch" - new_version = Reissue.call(segment:, version_file:, version_limit:, version_redo_proc:) + new_version = formatter.call(segment:, version_file:, version_limit:, version_redo_proc:) if defined?(Bundler) Bundler.with_unbundled_env do system("bundle install") @@ -102,17 +107,17 @@ def define end system("git add -u") - if updated_paths.any? + if updated_paths&.any? system("git add #{updated_paths.join(" ")}") end bump_message = "Bump version to #{new_version}" if commit if reissue_version_with_branch? - Rake::Task["#{name}:branch"].invoke("reissue/#{new_version}") + tasker["#{name}:branch"].invoke("reissue/#{new_version}") end system("git commit -m '#{bump_message}'") - Rake::Task["#{name}:push"].invoke if push_reissue? + tasker["#{name}:push"].invoke if push_reissue? else system("echo '#{bump_message}'") end @@ -127,19 +132,19 @@ def define else args[:version_limit].to_i end - Reissue.reformat(changelog_file, version_limit:) + formatter.reformat(changelog_file, version_limit:) end desc "Finalize the changelog for an unreleased version to set the release date." task "#{name}:finalize", [:date] do |task, args| date = args[:date] || Time.now.strftime("%Y-%m-%d") - version, date = Reissue.finalize(date, changelog_file:) + version, date = formatter.finalize(date, changelog_file:) finalize_message = "Finalize the changelog for version #{version} on #{date}" if commit_finalize - Rake::Task["#{name}:branch"].invoke("reissue/#{version}") if finalize_with_branch? + tasker["#{name}:branch"].invoke("reissue/#{version}") if finalize_with_branch? system("git add -u") system("git commit -m '#{finalize_message}'") - Rake::Task["#{name}:push"].invoke if push_finalize? + tasker["#{name}:push"].invoke if push_finalize? else system("echo '#{finalize_message}'") end