Class: LicenseAcceptance::FileAcceptance
- Inherits:
-
Object
- Object
- LicenseAcceptance::FileAcceptance
- Includes:
- Logger
- Defined in:
- lib/license_acceptance/file_acceptance.rb
Constant Summary collapse
- INVOCATION_TIME =
DateTime.now.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#accepted?(product_relationship) ⇒ Boolean
For all the given products in the product set, search all possible locations for the license acceptance files.
-
#initialize(config) ⇒ FileAcceptance
constructor
A new instance of FileAcceptance.
- #persist(product_relationship, missing_licenses) ⇒ Object
Methods included from Logger
Constructor Details
#initialize(config) ⇒ FileAcceptance
Returns a new instance of FileAcceptance.
13 14 15 |
# File 'lib/license_acceptance/file_acceptance.rb', line 13 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/license_acceptance/file_acceptance.rb', line 11 def config @config end |
Instance Method Details
#accepted?(product_relationship) ⇒ Boolean
For all the given products in the product set, search all possible locations for the license acceptance files.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/license_acceptance/file_acceptance.rb', line 21 def accepted?(product_relationship) searching = [product_relationship.parent] + product_relationship.children missing_licenses = searching.clone logger.debug("Searching for the following licenses: #{missing_licenses.map(&:name)}") searching.each do |product| found = false config.license_locations.each do |loc| f = File.join(loc, product.filename) if File.exist?(f) found = true logger.debug("Found license #{product.filename} at #{f}") missing_licenses.delete(product) break end end break if missing_licenses.empty? end logger.debug("Missing licenses remaining: #{missing_licenses.map(&:name)}") missing_licenses end |
#persist(product_relationship, missing_licenses) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/license_acceptance/file_acceptance.rb', line 43 def persist(product_relationship, missing_licenses) parent = product_relationship.parent parent_version = product_relationship.parent_version root_dir = config.persist_location if !Dir.exist?(root_dir) begin FileUtils.mkdir_p(root_dir) rescue StandardError => e msg = "Could not create license directory #{root_dir}" logger.info "#{msg}\n\t#{e.message}\n\t#{e.backtrace.join("\n\t")}" return [e] end end errs = [] if missing_licenses.include?(parent) err = persist_license(root_dir, parent, parent, parent_version) errs << err unless err.nil? end product_relationship.children.each do |child| if missing_licenses.include?(child) err = persist_license(root_dir, child, parent, parent_version) errs << err unless err.nil? end end return errs end |