Module: License::Compatibility

Defined in:
lib/license/compatibility.rb,
lib/license/compatibility/version.rb

Constant Summary collapse

VERSION =
"1.4.0"

Class Method Summary collapse

Class Method Details

.forward_compatiblity(source_license, derivative_license) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/license/compatibility.rb', line 6

def self.forward_compatiblity(source_license, derivative_license)
  souce_type = license_type(source_license)
  derivative_type = license_type(derivative_license)
  case souce_type
  when :public_domain
    return true
  when :permissive, :weak_copyleft
    [:public_domain, :permissive, :weak_copyleft, :copyleft, :strong_copyleft, :network_copyleft].include? derivative_type
  when :strong_copyleft
    [:weak_copyleft, :strong_copyleft, :network_copyleft].include? derivative_type
  when :network_copyleft
    [:network_copyleft].include? derivative_type
  else
    raise 'Unknown license compatiblity'
  end
end

.license_dataObject



23
24
25
# File 'lib/license/compatibility.rb', line 23

def self.license_data
  @@license_data ||= JSON.load(File.read(File.expand_path('../licenses.json', __FILE__)))
end

.license_type(license) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/license/compatibility.rb', line 27

def self.license_type(license)
  license = license.gsub('+', '')
  if license_data['public_domain'].include?(license)
    :public_domain
  elsif license_data['permissive'].include?(license)
    :permissive
  elsif license_data['weak_copyleft'].include?(license)
    :weak_copyleft
  elsif license_data['strong_copyleft'].include?(license)
    :strong_copyleft
  elsif license_data['network_copyleft'].include?(license)
    :network_copyleft
  else
    raise 'Unknown license type'
  end
end