class License

Overview

A simple class interface for managing licenses.

Included Modules

Defined in:

license.cr

Constant Summary

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

Class Method Summary

Instance Method Summary

Macro Summary

Constructor Detail

def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

[View source]

Class Method Detail

def self.init : Nil #

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


[View source]
def self.licenses : Array(License) #

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.


[View source]

Instance Method Detail

def body : String #

[View source]
def conditions : Conditions #

A Conditions enum containing the conditions permitted by the license.


[View source]
def description : String #

The description of the license.


[View source]
def limitations : Limitations #

A Limitations enum containing the limitations enforced by the license.


[View source]
def nickname : String | Nil #

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


[View source]
def permissions : Permissions #

A Permissions enum containing the permissions for the license.


[View source]
def 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 ..."

[View source]
def 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 ..."

[View source]
def spdx_id : String #

[View source]
def title : String #

The title of the license.


[View source]
def used_by : Hash(String, String) #

[View source]

Macro Detail

macro 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

[View source]
macro 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

[View source]
macro load_all #

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


[View source]
macro 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

[View source]