-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
/
Copy pathlicense.rb
70 lines (59 loc) · 2.18 KB
/
license.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class Cask::DSL::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,
:commercial => :closed,
:gratis => :closed,
:abandoned => :closed, # undocumented, should not be used yet
:freemium => :closed, # undocumented, should not be used yet
:trial => :closed, # undocumented, should not be used yet
:oss => :oss,
:affero => :oss,
:apache => :oss,
:arphic => :oss,
:artistic => :oss,
:bsd => :oss,
:cc => :oss,
:eclipse => :oss,
:gpl => :oss,
:isc => :oss,
:lppl => :oss,
:ncsa => :oss,
:mit => :oss,
:mpl => :oss,
:ofl => :oss,
:public_domain => :oss,
:ubuntu_font => :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