The letter A styled as Alchemists logo. lchemists Syndication Icon

Putin's War on Ukraine - Watch President Zelenskyy's speech and help Ukraine fight against the senseless cruelty of a dictator!

Published January 29, 2022 Updated May 7, 2022
Spek Icon

Spek

0.3.0

Spek is short for specification and enhances Ruby gem specifications with additional information and tooling. You can use this library as foundational support to build on top of with your own enhancements.

Features

  • Supports finding gems by name.

  • Supports loading gems by path to specification.

  • Supports picking gems by name with optional version selection.

  • Supports semantic versions via Versionaire.

Requirements

  1. Ruby.

Setup

To set up the project, run:

bin/setup

Usage

This gem makes interacting with Ruby gems easier by providing foundational objects for which you can built on top of. Gemsmith is built on top of this gem if you need working example.

Presenter

This object wraps a Gem::Specification for presentation, provides semantic versioning, direct access to metadata information, pathnames, and other enriched information. You can obtain an instance via the following code:

specification = Gem::Specification.new do |spec|
  spec.name = "test"
  spec.version = "0.0.0"
  spec.authors = "Jill Smith"
  spec.summary = "A test summary."
end

presenter = Spek::Presenter.new specification

The presenter is a read-only object so you’ll only have access to getter methods which are mostly documented here. Please note that not all methods map one-to-one so you’ll want to look at the public API of this object for further details.

Loader

When given a path to a gem specification file, the loader will load a gem specification for you. Example:

presenter = Spek::Loader.call "path/to/my/test.gemspec"
presenter.class  # Spek::Presenter

Finder

The finder will find all gem specifications for a given name. Example:

presenters = Spek::Finder.call "refinements"
presenters.map(&:class)  # [Spek::Presenter]

Picker

When given a gem name, this will allow you pick from a list of gem versions if any. Otherwise, if multiple versions don’t exist, the first version found will be answered instead. Example:

require "dry/monads"

include Dry::Monads[:result]

case Spek::Picker.call("refinements")
  in Success(specification) then puts "You selected: #{specification.name}."
  in Failure(error) then puts error
end

The picker always answers a monad so you can quickly pattern match for further action.

Versioner

When given a version and path, the versioner will update the version of your gem specification. Example:

specification = Spek::Versioner.call "1.0.0", "path/to/my/test.gemspec"
specification.version  # <struct Versionaire::Version major=1, minor=0, patch=0>

This makes it easier to automate the updating of your gem specification version information.

Development

You can also use the IRB console for direct access to all objects:

bin/console

Tests

To test, run:

bundle exec rake

Credits