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



6
7
8
# File 'lib/license_finder/package_utils/licensing.rb', line 6

def decided_licenses
  @decided_licenses
end

#license_filesObject

Returns the value of attribute license_files

Returns:

  • (Object)

    the current value of license_files



6
7
8
# File 'lib/license_finder/package_utils/licensing.rb', line 6

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



6
7
8
# File 'lib/license_finder/package_utils/licensing.rb', line 6

def licenses_from_spec
  @licenses_from_spec
end

#packageObject

Returns the value of attribute package

Returns:

  • (Object)

    the current value of package



6
7
8
# File 'lib/license_finder/package_utils/licensing.rb', line 6

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.



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

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



18
19
20
21
# File 'lib/license_finder/package_utils/licensing.rb', line 18

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

#activations_from_filesObject



28
29
30
31
32
# File 'lib/license_finder/package_utils/licensing.rb', line 28

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

#activations_from_specObject



23
24
25
26
# File 'lib/license_finder/package_utils/licensing.rb', line 23

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

#default_activationObject



34
35
36
37
# File 'lib/license_finder/package_utils/licensing.rb', line 34

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