Method: LicenseAcceptance::ProductReader#read

Defined in:
lib/license_acceptance/product_reader.rb

#readObject

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/license_acceptance/product_reader.rb', line 12

def read
  logger.debug("Reading products and relationships...")
  location = get_location
  self.products = {}
  self.relationships = {}

  toml = Tomlrb.load_file(location, symbolize_keys: false)
  raise InvalidProductInfo.new(location) if toml.empty? || toml["products"].nil? || toml["relationships"].nil?

  toml["products"].each do |product|
    products[product["id"]] = Product.new(
      product["id"], product["pretty_name"],
      product["filename"], product["mixlib_name"],
      product["license_required_version"]
    )
  end

  toml["relationships"].each do |parent_id, children|
    parent = products[parent_id]
    raise UnknownParent.new(parent_id) if parent.nil?
    # Its fine to not have a relationship entry, but not fine to have
    # a relationship where the children are nil or empty.
    if children.nil? || children.empty? || !children.is_a?(Array)
      raise NoChildRelationships.new(parent)
    end

    children.map! do |child_id|
      child = products[child_id]
      raise UnknownChild.new(child_id) if child.nil?

      child
    end
    relationships[parent] = children
  end

  logger.debug("Successfully read products and relationships")
end