Documentation
¶
Overview ¶
Package gem extracts packages from Ruby .gem archives.
Index ¶
- Constants
- func New(cfg *cpb.PluginConfig) (filesystem.Extractor, error)
- func NormalizeTwiddleWakka(v string) string
- func ResolveDependencyVersion(reqs []RequirementConstraint) (string, bool)
- func ToProto(m *RubyGemMetadata) *pb.RubyGemMetadata
- type Dependency
- type Extractor
- type Requirement
- type RequirementConstraint
- type RubyGemMetadata
Constants ¶
const (
// Name is the unique name of this extractor.
Name = "ruby/gem"
)
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(cfg *cpb.PluginConfig) (filesystem.Extractor, error)
New returns a Ruby gem extractor.
func NormalizeTwiddleWakka ¶
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 ¶
Extractor extracts Ruby packages from .gem archives.
func (Extractor) Extract ¶
func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) (inventory.Inventory, error)
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) Requirements ¶
func (e Extractor) Requirements() *plugin.Capabilities
Requirements 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:
- 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.
- 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.