gem

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2026 License: Apache-2.0, BSD-3-Clause, MIT Imports: 22 Imported by: 0

Documentation

Overview

Package gem extracts packages from Ruby .gem archives.

Index

Constants

View Source
const (
	// Name is the unique name of this extractor.
	Name = "ruby/gem"
)

Variables

This section is empty.

Functions

func New

New returns a Ruby gem extractor.

func NormalizeTwiddleWakka

func NormalizeTwiddleWakka(v string) string

NormalizeTwiddleWakka normalizes a version constraint for the pessimistic operator (~>). - "x" -> "x.0.0" - "x.y" -> "x.y.0" - "x.y.z" or more -> "x.y.z..."

func ResolveDependencyVersion

func ResolveDependencyVersion(reqs []RequirementConstraint) (string, bool)

ResolveDependencyVersion extracts the minimum lower-bound version from a list of constraints. It considers constraints with "=", ">=", and "~>". For "~> x", the version is normalized to "x.0.0". For "~> x.y", the version is normalized to "x.y.0". For "~> x.y.z", the version is kept as "x.y.z". If multiple qualifying lower-bound constraints exist, the highest version is selected. Returns (version, true) if a valid lower bound is found, or ("", false) if none exist.

func ToProto

func ToProto(m *RubyGemMetadata) *pb.RubyGemMetadata

ToProto converts RubyGemMetadata struct to RubyGemMetadata proto.

Types

type Dependency

type Dependency struct {
	Name                string       `json:"name"                 yaml:"name"`
	Type                string       `json:"type"                 yaml:"type"`
	Requirement         *Requirement `json:"requirement"          yaml:"requirement"`
	VersionRequirements *Requirement `json:"version_requirements" yaml:"version_requirements"`
	Prerelease          bool         `json:"prerelease"           yaml:"prerelease"`
}

Dependency represents a dependency declared in a gem specification.

func (*Dependency) IsRuntime

func (d *Dependency) IsRuntime() bool

IsRuntime returns true if the dependency is a runtime dependency.

func (*Dependency) Requirements

func (d *Dependency) Requirements() []RequirementConstraint

Requirements returns the slice of requirement constraints.

type Extractor

type Extractor struct {
	Stats stats.Collector
	// contains filtered or unexported fields
}

Extractor extracts Ruby packages from .gem archives.

func (Extractor) Extract

Extract extracts packages from the .gem file.

func (Extractor) FileRequired

func (e Extractor) FileRequired(api filesystem.FileAPI) bool

FileRequired returns true if the specified file matches .gem.

func (Extractor) Name

func (e Extractor) Name() string

Name of the extractor.

func (Extractor) Requirements

func (e Extractor) Requirements() *plugin.Capabilities

Requirements of the extractor.

func (Extractor) Version

func (e Extractor) Version() int

Version of the extractor.

type Requirement

type Requirement struct {
	Requirements []RequirementConstraint `json:"requirements" yaml:"requirements"`
}

Requirement holds a list of requirement constraints.

type RequirementConstraint

type RequirementConstraint struct {
	Operator string `json:"operator"`
	Version  string `json:"version"`
}

RequirementConstraint represents an individual [operator, version] pair.

func (*RequirementConstraint) UnmarshalYAML

func (c *RequirementConstraint) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML unmarshals a [operator, version] sequence node from YAML. In RubyGems metadata, each dependency requirement is serialized as a two-element sequence: [operator, version]. The version element can appear in two distinct shapes:

  1. Ruby Object Mapping (!ruby/object:Gem::Version): Standard format produced by Psych (Ruby's YAML serializer). The AST node is a yaml.MappingNode with child keys, where the version string lives under the "version" key (e.g. version: '2.0'). The node's top-level Value string is empty.
  2. Plain Scalar String: Alternative/legacy format or simplified YAML where the version is a direct scalar string (e.g. '2.0'). The AST node is a yaml.ScalarNode.

We decode using gemVersionWrapper, which handles both mapping nodes and scalar nodes.

type RubyGemMetadata

type RubyGemMetadata struct {
	Authors      []string      `json:"authors,omitempty"`
	Description  string        `json:"description,omitempty"`
	Homepage     string        `json:"homepage,omitempty"`
	Licenses     []string      `json:"licenses,omitempty"`
	Dependencies []*Dependency `json:"dependencies,omitempty"`
	Platform     string        `json:"platform,omitempty"`
	Summary      string        `json:"summary,omitempty"`
}

RubyGemMetadata contains metadata fields extracted from a Ruby gem specification.

func ToStruct

func ToStruct(p *pb.RubyGemMetadata) *RubyGemMetadata

ToStruct converts RubyGemMetadata proto to RubyGemMetadata struct.

func (*RubyGemMetadata) IsProtoable

func (m *RubyGemMetadata) IsProtoable()

IsProtoable marks the struct as a metadata type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL