mirror of
https://github.com/donl/homebrew-cask-versions.git
synced 2026-07-17 06:16:47 -06:00
References: #4688. For forward-compatibility; intentionally left undocumented. The `license` stanza is not free-form. There is a limited set of valid symbols, of which the argument must be a member. (The set will later be documented, and probably needs amendments.) Version numbers and variants of licenses are intentionally ommitted. The use-case for `license` is filtering and listing of Casks. We want to avoid becoming a detailed repository of application descriptions: that information can be found at the `homepage` URL.
67 lines
1.9 KiB
Ruby
67 lines
1.9 KiB
Ruby
class Cask::License
|
|
|
|
# a generic category can always be given as a license, so
|
|
# category names should be given as both key and value
|
|
VALID_LICENSES = {
|
|
# license category
|
|
:unknown => :unknown,
|
|
|
|
:other => :other,
|
|
|
|
:closed => :closed,
|
|
:abandoned => :closed,
|
|
:commercial => :closed,
|
|
:free => :closed,
|
|
:trial => :closed,
|
|
|
|
:oss => :oss,
|
|
:affero => :oss,
|
|
:apache => :oss,
|
|
:arphic => :oss,
|
|
:artistic => :oss,
|
|
:bsd => :oss,
|
|
:cc => :oss,
|
|
:eclipse => :oss,
|
|
:gpl => :oss,
|
|
:isc => :oss,
|
|
:mit => :oss,
|
|
:mpl => :oss,
|
|
:ofl => :oss,
|
|
:public_domain => :oss,
|
|
:ubuntu => :oss,
|
|
:x11 => :oss,
|
|
}
|
|
|
|
DEFAULT_LICENSE = :unknown
|
|
DEFAULT_CATEGORY = VALID_LICENSES[DEFAULT_LICENSE]
|
|
|
|
attr_reader :value
|
|
|
|
def self.check_constants
|
|
categories = Set.new(VALID_LICENSES.values)
|
|
categories.each do |cat|
|
|
next if VALID_LICENSES.key?(cat)
|
|
raise "license category is not a value: '#{@cat.inspect}'"
|
|
end
|
|
end
|
|
|
|
def self.category(_license)
|
|
VALID_LICENSES.fetch(_license, DEFAULT_CATEGORY)
|
|
end
|
|
|
|
def initialize(arg)
|
|
@value = arg
|
|
@value = DEFAULT_LICENSE if @value.nil?
|
|
unless VALID_LICENSES.key?(@value)
|
|
raise "invalid license value: '#{@value.inspect}'"
|
|
end
|
|
end
|
|
|
|
def category
|
|
self.class.category(@value)
|
|
end
|
|
|
|
def to_s
|
|
@value.inspect
|
|
end
|
|
end
|