class License
- License
- Reference
- Object
Overview
A simple class interface for managing licenses.
Included Modules
- YAML::Serializable
Defined in:
license.crConstant 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
-
.init : Nil
Loads all available licenses at compile time and initializes the
.licenses
method. -
.licenses : Array(License)
An array of all available licenses.
Instance Method Summary
- #body : String
-
#conditions : Conditions
A
Conditions
enum containing the conditions permitted by the license. -
#description : String
The description of the license.
-
#limitations : Limitations
A
Limitations
enum containing the limitations enforced by the license. -
#nickname : String | Nil
The nickname of the license.
-
#permissions : Permissions
A
Permissions
enum containing the permissions for the license. -
#render(io : IO, *, year = nil, author = nil) : Nil
Renders the license content to the io.
-
#render(*, year = nil, author = nil) : String
Renders the license content and returns a string.
- #spdx_id : String
-
#title : String
The title of the license.
- #used_by : Hash(String, String)
Macro Summary
-
load(id)
Loads a license by its SPDX identifier at compile time.
-
load(*ids)
Returns an array of licenses loaded by their SPDX identifiers at compile time.
-
load_all
Returns an array of all available licenses loaded at compile time.
-
render(id, *, year = nil, author = nil)
Returns a string of the license rendered at compile time.
Constructor Detail
Class Method Detail
Loads all available licenses at compile time and initializes the .licenses
method.
This method must be ran before attempting to use the .licenses
method.
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.
Instance Method Detail
A Limitations
enum containing the limitations enforced by the license.
The nickname of the license. This is generally a variation of the license name or SPDX ID.
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 ..."
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 ..."
Macro Detail
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
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
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