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
17
# 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



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

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

#activations_from_filesObject



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

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



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

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

#default_activationObject



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

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