All Projects → bkuhlmann → versionaire

bkuhlmann / versionaire

Licence: other
Provides an immutable, thread-safe, and semantic version type.

Programming Languages

ruby
36898 projects - #4 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to versionaire

Squot
Squeak Object Tracker - Version control for arbitrary objects, currently with Git storage
Stars: ✭ 45 (-36.62%)
Mutual labels:  version-control, versioning
python-aos-lesson
Python for Atmosphere and Ocean Scientists
Stars: ✭ 78 (+9.86%)
Mutual labels:  version-control, versioning
tag
Git utility to create tags in order to identify specific releases
Stars: ✭ 24 (-66.2%)
Mutual labels:  version-control, versioning
speckle-unity
AEC Interoperability for Unity through Speckle
Stars: ✭ 28 (-60.56%)
Mutual labels:  version-control, versioning
Git Novice
Version Control with Git
Stars: ✭ 227 (+219.72%)
Mutual labels:  version-control, versioning
gtbump
git tag bump: A simple utility to bump and manage git semantic version tags and generate Markdown changelogs.
Stars: ✭ 15 (-78.87%)
Mutual labels:  version-control, versioning
Python Aos Lesson
Python for Atmosphere and Ocean Scientists
Stars: ✭ 49 (-30.99%)
Mutual labels:  version-control, versioning
Json Git
A pure JS local Git to versionize any JSON
Stars: ✭ 109 (+53.52%)
Mutual labels:  version-control, versioning
Sketch Json
Transform sketch files to json and json to sketch files
Stars: ✭ 113 (+59.15%)
Mutual labels:  version-control, versioning
Git
Useful Git commands.
Stars: ✭ 109 (+53.52%)
Mutual labels:  version-control, versioning
QuitStore
🖧 Quads in Git - Distributed Version Control for RDF Knowledge Bases
Stars: ✭ 87 (+22.54%)
Mutual labels:  version-control, versioning
clearml-server-helm
ClearML Server for Kubernetes Clusters Using Helm
Stars: ✭ 18 (-74.65%)
Mutual labels:  version-control, versioning
AutoVer
Configurable automatic or real time backup and personal versioning system
Stars: ✭ 65 (-8.45%)
Mutual labels:  version-control, versioning
pro.fessional.wings
WingsBoot=BKB+飞鞋+SpringBoot。其核心价值是:①使团队快速实现业务目标;②快速偿还技术债务;③安全的面向程序和业务重构。
Stars: ✭ 78 (+9.86%)
Mutual labels:  version-control
neptune-client
📒 Experiment tracking tool and model registry
Stars: ✭ 348 (+390.14%)
Mutual labels:  versioning
ongeza
An automated way to follow the Semantic Versioning Specification
Stars: ✭ 36 (-49.3%)
Mutual labels:  versioning
gradle-semantic-build-versioning
Gradle plugin to generate version-numbers and tags using semantic versioning
Stars: ✭ 19 (-73.24%)
Mutual labels:  versioning
deblibs-gradle-plugin
A Gradle plugin that creates Github issue and Slack message for outdated dependencies so they can easily be tracked and manually upgraded.
Stars: ✭ 73 (+2.82%)
Mutual labels:  versioning
nb-clean
Clean Jupyter notebooks of outputs, metadata, and empty cells, with Git integration
Stars: ✭ 72 (+1.41%)
Mutual labels:  version-control
dot
distributed data sync with operational transformation/transforms
Stars: ✭ 73 (+2.82%)
Mutual labels:  versioning

Versionaire

Ruby doesn’t provide a primitive version type by default so Versionaire fills this gap by providing immutable and thread-safe Semantic Versioning so you can leverage versions within your applications. This new Version type behaves and feels a lot like other primitives (i.e. String, Array, Hash, etc) and can even be cast/converted from other primitives.

Features

  • Provides strict Semantic Versioning which means <major>.<minor>.<patch>.

  • Provides immutable, thread-safe version instances.

  • Converts (casts) from a String, Array, Hash, or Version to a Version.

  • Disallows <major>.<minor>.<patch>-<pre-release> usage even though Semantic Versioning suggests that you may use pre-release information.

  • Disallows <major>.<minor>.<patch>+<build_metadata> usage even though Semantic Versioning suggests that you may use build metadata.

Screencasts

Screencast

Requirements

  1. Ruby.

Setup

To install, run:

gem install versionaire

Add the following to your Gemfile:

gem "versionaire"

Usage

Initialization

A new version can be initialized in a variety of ways:

Versionaire::Version.new                            # "0.0.0"
Versionaire::Version[major: 1]                      # "1.0.0"
Versionaire::Version[major: 1, minor: 2]            # "1.2.0"
Versionaire::Version[major: 1, minor: 2, patch: 3]  # "1.2.3"

Equality

Value (#==)

Equality is deterimined by the state of the object. This means that a version is equal to another version as long as all of the values (i.e. state) are equal to each other. Example:

version_a = Versionaire::Version[major: 1]
version_b = Versionaire::Version[major: 2]
version_c = Versionaire::Version[major: 1]

version_a == version_a  # true
version_a == version_b  # false
version_a == version_c  # true

Knowning this, versions can be compared against one another too:

version_a > version_b                    # false
version_a < version_b                    # true
version_a.between? version_c, version_b  # true

Hash (#eql?)

Behaves exactly as #==.

Case (#===)

Behaves exactly as #==.

Identity (#equal?)

Works like any other standard Ruby object where an object is equal only to itself.

version_a = Versionaire::Version[major: 1]
version_b = Versionaire::Version[major: 2]
version_c = Versionaire::Version[major: 1]

version_a.equal? version_a  # true
version_a.equal? version_b  # false
version_a.equal? version_c  # false

Conversions

Function

Use the Versionaire::Version function to explicitly cast to a version:

version = Versionaire::Version[major: 1]

Versionaire::Version "1.0.0"
Versionaire::Version [1, 0, 0]
Versionaire::Version major: 1, minor: 0, patch: 0
Versionaire::Version version

Each of these conversions will result in a version object that represents “1.0.0”. When attempting to convert an unsupported type, a Versionaire::Errors::Cast exception will be thrown.

Refinement

Building upon the examples shown above, there is an even more elegant solution where you can use this gem’s built-in refinement support:

using Versionaire::Cast

version = Versionaire::Version[major: 1]

Version "1.0.0"
Version [1, 0, 0]
Version major: 1, minor: 0, patch: 0
Version version

By adding using Versionaire::Cast to your implementation, this allows Versionaire to refine Kernel so you have a top-level Version conversion function much like Kernel’s native support for Integer, String, Array, Hash, etc. The benefit to this approach is it reduces the amount of typing, doesn’t pollute your entire object space like a monkey patch would, and provides a idiomatic approach to casting like any other primitive.

Implicit

Implicit conversion to a String is supported:

"1.0.0".match Versionaire::Version[major: 1]  # <MatchData "1.0.0">

Explicit

Explicit conversion to a String, Array, Hash, or Proc is supported:

version = Versionaire::Version.new

version.to_s     # "0.0.0"
version.to_a     # [0, 0, 0]
version.to_h     # {major: 0, minor: 0, patch: 0}
version.to_proc  # #<Proc:0x000000010b015b88 (lambda)>

To elaborate on procs further, this means the following is possible:

using Versionaire::Cast

version = Version "1.2.3"

version.to_proc.call :major               # 1
[version, version, version].map(&:minor)  # [2, 2, 2]

Inspections

You can inspect a version which is the equivalent of an escaped string representation. Example:

using Versionaire::Cast

Version("1.2.3").inspect  # "\"1.2.3\""

Comparisons

All versions are comparable which means any of the operators from the Comparable module will work. Example:

version_1 = Versionaire::Version "1.0.0"
version_2 = Versionaire::Version "2.0.0"

version_1 < version_2                    # true
version_1 <= version_2                   # true
version_1 == version_2                   # false (see Equality section above for details)
version_1 > version_2                    # false
version_1 >= version_2                   # false
version_1.between? version_1, version_2  # true
version_1.clamp version_1, version_2     # version_1 (added in Ruby 2.4.0)

Math

Versions can be added, subtracted, sequentially increased, or sequentially decreased from each other.

Addition

Versions can be added together to produce a resulting version sum.

version_1 = Versionaire::Version[major: 1, minor: 2, patch: 3]
version_2 = Versionaire::Version[major: 2, minor: 5, patch: 7]
version_1 + version_2  # "3.7.10"

Subtraction

Versions can be substracted from each other as long as there isn’t a negative result.

version_1 = Versionaire::Version[major: 1, minor: 2, patch: 3]
version_2 = Versionaire::Version[major: 1, minor: 1, patch: 1]
version_1 - version_2  # "0.1.2"

version_1 = Versionaire::Version[major: 1]
version_2 = Versionaire::Version[major: 5]
version_1 - version_2  # Versionaire::Errors::NegativeNumber

Up

Versions can be sequentially increased or given a specific version to jump to.

version = Versionaire::Version[major: 1, minor: 1, patch: 1]
version.up :major     # => "2.1.1"
version.up :major, 3  # => "4.1.1"
version.up :minor     # => "1.2.1"
version.up :minor, 3  # => "1.4.1"
version.up :patch     # => "1.1.2"
version.up :patch, 3  # => "1.1.4"

Down

Versions can be sequentially decreased or given a specific version to jump to as long as the result is not negative.

version = Versionaire::Version[major: 5, minor: 5, patch: 5]
version.down :major     # => "4.5.5"
version.down :major, 3  # => "2.5.5"
version.down :minor     # => "5.4.5"
version.down :minor, 3  # => "5.2.5"
version.down :patch     # => "5.5.4"
version.down :patch, 3  # => "5.5.2"
version.down :major, 6  # => Versionaire::Errors::NegativeNumber

Extensions

This project supports libraries which might desire native Version types. Each extension must be explicitly required in order to be used since they are optional by default. See below for details.

OptionParser

OptionParser is one of Ruby’s default gems which can accept additional types not native to Ruby by default. To extend OptionParser with the Version type, all you need to do is add these two lines to your implementation:

  1. require "versionaire/extensions/option_parser" - This will load dependencies and register the Version type with OptionParser.

  2. instance.on "--tag VERSION", Versionaire::Version - Specifying Versionaire::Version as the second argument will ensure OptionParser properly casts command line input as a Version type.

Here’s an example implementation that demonstrates full usage:

require "versionaire/extensions/option_parser"

options = {}

parser = OptionParser.new do |instance|
  instance.on "--tag VERSION", Versionaire::Version, "Casts to version." do |value|
    options[:version] = value
  end
end

parser.parse! %w[--tag 1.2.3]
puts options

The above will ensure --tag 1.2.3 is parsed as {:version⇒#<struct Versionaire::Version major=1, minor=2, patch=3>} within your options variable. Should OptionParser parse an invalid version, you’ll get a OptionParser::InvalidArgument instead.

Development

To contribute, run:

git clone https://github.com/bkuhlmann/versionaire
cd versionaire
bin/setup

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

bin/console

Tests

To test, run:

bundle exec rake

Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].