Class: LicenseFinder::Licensing

Inherits:
Struct
  • Object
show all
Defined in:
lib/license_finder/package_utils/licensing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#decided_licensesObject

Returns the value of attribute decided_licenses

Returns:

  • (Object)

    the current value of decided_licenses



4
5
6
# File 'lib/license_finder/package_utils/licensing.rb', line 4

def decided_licenses
  @decided_licenses
end

#license_filesObject

Returns the value of attribute license_files

Returns:

  • (Object)

    the current value of license_files



4
5
6
# File 'lib/license_finder/package_utils/licensing.rb', line 4

def license_files
  @license_files
end

#licenses_from_specObject

Returns the value of attribute licenses_from_spec

Returns:

  • (Object)

    the current value of licenses_from_spec



4
5
6
# File 'lib/license_finder/package_utils/licensing.rb', line 4

def licenses_from_spec
  @licenses_from_spec
end

#packageObject

Returns the value of attribute package

Returns:

  • (Object)

    the current value of package



4
5
6
# File 'lib/license_finder/package_utils/licensing.rb', line 4

def package
  @package
end

Instance Method Details

#activationsObject

Implements the algorithm for choosing the right set of licenses from among the various sources of licenses we know about. In order of priority, licenses come from decisions, package specs, or package files.



8
9
10
11
12
13
14
# File 'lib/license_finder/package_utils/licensing.rb', line 8

def activations
  if activations_from_decisions.any? then activations_from_decisions
  elsif activations_from_spec.any?      then activations_from_spec
  elsif activations_from_files.any?     then activations_from_files
  else [default_activation]
  end
end

#activations_from_decisionsObject



16
17
18
19
# File 'lib/license_finder/package_utils/licensing.rb', line 16

def activations_from_decisions
  @afd ||= decided_licenses
           .map { |license| Activation::FromDecision.new(package, license) }
end

#activations_from_filesObject



26
27
28
29
30
# File 'lib/license_finder/package_utils/licensing.rb', line 26

def activations_from_files
  @aff ||= license_files
           .group_by(&:license)
           .map { |license, files| Activation::FromFiles.new(package, license, files) }
end

#activations_from_specObject



21
22
23
24
# File 'lib/license_finder/package_utils/licensing.rb', line 21

def activations_from_spec
  @afs ||= licenses_from_spec
           .map { |license| Activation::FromSpec.new(package, license) }
end

#default_activationObject



32
33
34
35
# File 'lib/license_finder/package_utils/licensing.rb', line 32

def default_activation
  default_license = License.find_by_name nil
  Activation::None.new(package, default_license)
end