class

License

Inherits YAML::Serializable < Reference < Object

A simple class interface for managing licenses.

Constants

IDENTIFIERS = {"0bsd", "afl-3.0", "agpl-3.0", "apache-2.0", "artistic-2.0", "bsd-2-clause", "bsd-3-clause-clear", "bsd-3-clause", "bsd-4-clause", "bsl-1.0", "lgpl-2.1", "lgpl-3.0", "mit-0", "mit", "mpl-2.0", "wtfpl"}

A tuple of all available licenses.

VERSION = "0.1.0"

Constructors

new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
Source
new(*, __context_for_yaml_serializable ctx : YAML::ParseContext, __node_for_yaml_serializable node : YAML::Nodes::Node)
Source

Class methods

init

Loads all available licenses at compile time and initializes the licenses method. This method must be ran before attempting to use the licenses method.

Source
licenses

An array of all available licenses. This can only be used after running the License.init method which will load all available licenses at compile time. Attempting to use this method before loading will raise an exception.

Source

Instance methods

body

The license content (or body).

Source
conditions

A Conditions enum containing the conditions permitted by the license.

Source
description

The description of the license.

Source
limitations

A Limitations enum containing the limitations enforced by the license.

Source
nickname

The nickname of the license. This is generally a variation of the license name or SPDX ID.

Source
permissions

A Permissions enum containing the permissions for the license.

Source
render(io : IO, *, year = nil, author = nil) : Nil

Renders the license content to the io. If the year or author parameters are not specified, a default will be rendered in place.

io = IO::Memory.new
license = License.load "mit"
license.render io, year: 2023
io.to_s # => "MIT License ..."
Source
render(*, year = nil, author = nil) : String

Renders the license content and returns a string. If the year or author parameters are not specified, a default will be rendered in place.

license = License.load "mit"
license.render year: 2023 # => "MIT License ..."
Source
spdx_id

The SPDX license identifier. See https://spdx.org/licenses/ for more information.

Source
title

The title of the license.

Source
used_by

A hash of sources that use the license.

Source

Macros

load(id)

Loads a license by its SPDX identifier at compile time. If the license is not found, the program will not compile.

License.load "0bsd" # => #<License:0x...>
License.load "asdf" # => Error: Unknown license SPDX-ID: asdf
Source
load(*ids)

Returns an array of licenses loaded by their SPDX identifiers at compile time. If one of the licenses are not found, the program will not compile.

License.load "0bsd", "agpl-3.0" # => [#<License:0x...>, #<License:0x...>]
License.load "asdf"             # => Error: Unknown license SPDX-ID: asdf
Source
load_all

Returns an array of all available licenses loaded at compile time.

Source
render(id, *, year = nil, author = nil)

Returns a string of the license rendered at compile time. If the license is not found, the program will not compile.

License.render "mpl-2.0", year: 2023 # => "Mozilla Public License Version 2.0 ..."
License.render "asdf", year: 2023    # => Error: Unknown license SPDX-ID: asdf
Source

Nested types