Class: RubyGem

Inherits:
Object
  • Object
show all
Defined in:
lib/ratatui_ruby/devtools/tasks/bump/ruby_gem.rb

Overview

Coordinates version bumping across multiple manifests.

Ruby gems have versions in multiple files: version.rb, Cargo.toml, lockfiles. Bumping manually leads to mismatches. Forgetting the changelog produces incomplete releases.

This class orchestrates the bump. It updates all manifests, refreshes lockfiles, and updates the changelog. One command. Consistent versions.

Use it in rake tasks to bump major, minor, or patch versions.

Instance Method Summary collapse

Constructor Details

#initialize(manifests:, lockfile:, changelog:) ⇒ RubyGem

Creates a new RubyGem coordinator.

manifests

Array of Manifest objects. Exactly one must be primary.

lockfile

A lockfile object that responds to refresh.

changelog

A Changelog object for updating release notes.

Raises:

  • (ArgumentError)


24
25
26
27
28
29
# File 'lib/ratatui_ruby/devtools/tasks/bump/ruby_gem.rb', line 24

def initialize(manifests:, lockfile:, changelog:)
  raise ArgumentError, "Must have exactly one primary manifest" unless manifests.count(&:primary) == 1
  @manifests = manifests
  @lockfile = lockfile
  @changelog = changelog
end

Instance Method Details

#bump(segment) ⇒ Object

Bumps the version by the given segment.

Updates all manifests, refreshes lockfiles, and updates the changelog. Prints a suggested commit message.

segment

One of :major, :minor, or :patch.



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ratatui_ruby/devtools/tasks/bump/ruby_gem.rb', line 42

def bump(segment)
  target = version.next(segment)
  commit_message = @changelog.commit_message(target)

  puts "Bumping #{segment}: #{version} -> #{target}"
  @changelog.release(target)
  @manifests.each { |manifest| manifest.write(target) }
  @lockfile.refresh

  puts_commit_message(commit_message)
end

#set(version_string) ⇒ Object

Sets the version to an exact value.

Updates all manifests, refreshes lockfiles, and updates the changelog. Prints a suggested commit message.

version_string

A version string like "1.2.3".



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ratatui_ruby/devtools/tasks/bump/ruby_gem.rb', line 60

def set(version_string)
  target = SemVer.parse(version_string)
  commit_message = @changelog.commit_message(target)

  puts "Setting version: #{version} -> #{target}"
  @changelog.release(target)
  @manifests.each { |manifest| manifest.write(target) }
  @lockfile.refresh

  puts_commit_message(commit_message)
end

#versionObject

Returns the current version from the primary manifest.



32
33
34
# File 'lib/ratatui_ruby/devtools/tasks/bump/ruby_gem.rb', line 32

def version
  @manifests.find(&:primary).version
end