Class: Version

Inherits:
Object
  • Object
show all
Defined in:
lib/ratatui_ruby/devtools/tasks/website/version.rb

Overview

A documentation version for multi-version websites.

Documentation websites need to serve multiple versions. Users browse docs for their installed release. Maintainers preview trunk changes. Manually tracking git tags and branches is tedious.

This class discovers versions from git tags. It extracts source files at each ref. It provides metadata for version menus.

Use it to build multi-version documentation portals.

Direct Known Subclasses

Edge, Tagged

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allObject

Discovers all available versions.

Returns Edge (trunk) plus the latest patch for each minor version, sorted newest first.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ratatui_ruby/devtools/tasks/website/version.rb', line 26

def self.all
  tags = `git tag`.split.grep(/^v\d/)
  sorted_versions = tags.map { |t| Tagged.new(t) }
    .sort_by(&:semver)
    .reverse

  # Keep only the latest patch for each minor version
  # e.g., if we have v0.6.0, v0.6.1, v0.6.2, only keep v0.6.2
  latest_per_minor = sorted_versions
    .group_by { |v| v.semver.segments[0..1] } # group by [major, minor]
    .values
    .map(&:first) # take the first (highest patch) from each group

  [Edge.new] + latest_per_minor
end

Instance Method Details

#checkout(globs:, &block) ⇒ Object

Yields a temporary directory containing this version’s source.

Exports the git archive at the specified ref. Removes the native extension directory to avoid compilation issues.

globs

File patterns (unused, for API compatibility).



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ratatui_ruby/devtools/tasks/website/version.rb', line 68

def checkout(globs:, &block)
  Dir.mktmpdir do |path|
    # Use git archive to export the version at the specified ref
    # Pipe to tar to extract into the temporary directory
    system("git archive #{ref} | tar -x -C #{path}")

    # Remove the native extension directory as we don't need it for builds
    # and it can cause issues if not meant to be compiled in this context
    FileUtils.rm_rf("#{path}/ext")

    yield path
  end
end

#edge?Boolean

Returns true if this is the edge (trunk) version.

Returns:

  • (Boolean)


88
89
90
# File 'lib/ratatui_ruby/devtools/tasks/website/version.rb', line 88

def edge?
  false
end

#latest?Boolean

Returns true if this is the latest stable release.

Returns:

  • (Boolean)


83
84
85
# File 'lib/ratatui_ruby/devtools/tasks/website/version.rb', line 83

def latest?
  false
end

#nameObject

Human-readable name for version menus.

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/ratatui_ruby/devtools/tasks/website/version.rb', line 48

def name
  raise NotImplementedError
end

#refObject

Git ref (branch or tag) for checkout.

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/ratatui_ruby/devtools/tasks/website/version.rb', line 58

def ref
  raise NotImplementedError
end

#slugObject

URL-safe identifier for this version.

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/ratatui_ruby/devtools/tasks/website/version.rb', line 43

def slug
  raise NotImplementedError
end

#typeObject

Version type: :edge or :version.

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/ratatui_ruby/devtools/tasks/website/version.rb', line 53

def type
  raise NotImplementedError
end