Class: Y2Packager::ProductLicense

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
library/packages/src/lib/y2packager/product_license.rb

Overview

This class holds the license stuff for a given product

Why a separate ProductLicense class? First of all, we wanted to extract the license handling from Y2Packager::Product and moving this logic to Y2Packager::License was not a good idea because different products could share the same license. Additionally, this class offers an API to work with licenses when a proper Product or Addon object is not available (backward compatibility reasons).

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product_name, license) ⇒ ProductLicense

Constructor

Parameters:

  • product_name (String)
  • license (Yast::License)

78
79
80
81
82
83
# File 'library/packages/src/lib/y2packager/product_license.rb', line 78

def initialize(product_name, license)
  @product_name = product_name
  @license = license
  @handler = license.handler
  @fetcher = license.fetcher
end

Instance Attribute Details

#licenseLicense (readonly)

Returns Product's license.

Returns:


45
46
47
# File 'library/packages/src/lib/y2packager/product_license.rb', line 45

def license
  @license
end

Class Method Details

.clear_cacheObject

Clear product licenses cache


65
66
67
# File 'library/packages/src/lib/y2packager/product_license.rb', line 65

def clear_cache
  @cache = nil
end

.find(product_name, content: nil) ⇒ ProductLicense

Find license for a given product

This method uses a cache to return an already fetched product license.

Parameters:

  • product_name (String)

    Product's name

Returns:


55
56
57
58
59
60
61
62
# File 'library/packages/src/lib/y2packager/product_license.rb', line 55

def find(product_name, content: nil)
  return cache[product_name] if cache[product_name]

  license = License.find(product_name, content: content)
  return nil unless license

  cache[product_name] = ProductLicense.new(product_name, license)
end

Instance Method Details

#accept!Object

Accept the license

As a side effect, it will update the license acceptance


96
97
98
99
100
# File 'library/packages/src/lib/y2packager/product_license.rb', line 96

def accept!
  license.accept!
  sync_acceptance
  nil
end

#accepted?Boolean

Determine whether the license have been accepted or not

Returns:

  • (Boolean)

    true if the license has been accepted; false otherwise.


88
89
90
91
# File 'library/packages/src/lib/y2packager/product_license.rb', line 88

def accepted?
  sync_acceptance
  license.accepted?
end

#license_confirmation=(confirmed) ⇒ Object

Set the license confirmation for the product

Parameters:

  • confirmed (Boolean)

    true if it should be accepted; false otherwise


42
# File 'library/packages/src/lib/y2packager/product_license.rb', line 42

def_delegator :@handler, :confirmation=

#license_confirmation_required?Boolean

Determine whether the license should be accepted or not

Returns:

  • (Boolean)

    true if the license acceptance is required


37
# File 'library/packages/src/lib/y2packager/product_license.rb', line 37

def_delegator :@fetcher, :confirmation_required?

#reject!Object

Reject the license


103
104
105
106
107
# File 'library/packages/src/lib/y2packager/product_license.rb', line 103

def reject!
  license.reject!
  sync_acceptance
  nil
end