Module: License::Compatibility
- Defined in:
- lib/license/compatibility.rb,
lib/license/compatibility/version.rb
Constant Summary collapse
- VERSION =
"3.1.0"
Class Method Summary collapse
- .check_license_list(list) ⇒ Object
- .check_package_licence_list(list) ⇒ Object
- .filter_known_licenses(list) ⇒ Object
- .forward_compatibility(source_license, derivative_license) ⇒ Object
- .license_data ⇒ Object
- .license_type(license) ⇒ Object
Class Method Details
.check_license_list(list) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/license/compatibility.rb', line 63 def self.check_license_list(list) result = true self.filter_known_licenses(list).permutation(2).to_a.each { |couple| intermediate_result = self.forward_compatibility(couple[0], couple[1]) puts "#{couple[0]} is not forward-compatible with #{couple[1]}" unless intermediate_result result &= intermediate_result } puts "Licenses are compatible" if result result end |
.check_package_licence_list(list) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/license/compatibility.rb', line 74 def self.check_package_licence_list(list) result = true known_licenses = self.filter_known_licenses(list.map { |x| x[1] }) list.select { |x| known_licenses.include? x[1] }.permutation(2).to_a.each { |couple| intermediate_result = self.forward_compatibility(couple[0][1], couple[1][1]) puts "#{couple[0][0]} (#{couple[0][1]}) is not forward-compatible with #{couple[1][0]} (#{couple[1][1]})" unless intermediate_result result &= intermediate_result } puts "Licenses are compatible" if result result end |
.filter_known_licenses(list) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/license/compatibility.rb', line 48 def self.filter_known_licenses(list) known = [] list.each { |license | begin self.license_type(license) unless known.include? license known.push(license) end rescue => e STDERR.puts e end } return known end |
.forward_compatibility(source_license, derivative_license) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/license/compatibility.rb', line 10 def self.forward_compatibility(source_license, derivative_license) source_type = license_type(source_license) derivative_type = license_type(derivative_license) case source_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 compatibility: #{source_license} and #{derivative_license}" end end |
.license_data ⇒ Object
27 28 29 |
# File 'lib/license/compatibility.rb', line 27 def self.license_data @@license_data ||= JSON.load(File.read(File.('../licenses.json', __FILE__))) end |
.license_type(license) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/license/compatibility.rb', line 31 def self.license_type(license) license = license.delete('+') 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: #{license}" end end |