Class: LicenseAcceptance::ProductReader
- Inherits:
-
Object
- Object
- LicenseAcceptance::ProductReader
show all
- Includes:
- Logger
- Defined in:
- lib/license_acceptance/product_reader.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logger
initialize, logger, #logger
Instance Attribute Details
permalink
#products ⇒ Object
Returns the value of attribute products.
10
11
12
|
# File 'lib/license_acceptance/product_reader.rb', line 10
def products
@products
end
|
permalink
#relationships ⇒ Object
Returns the value of attribute relationships.
10
11
12
|
# File 'lib/license_acceptance/product_reader.rb', line 10
def relationships
@relationships
end
|
Instance Method Details
permalink
#get_location ⇒ Object
[View source]
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/license_acceptance/product_reader.rb', line 50
def get_location
if ENV["CHEF_LICENSE_PRODUCT_INFO"]
return ENV["CHEF_LICENSE_PRODUCT_INFO"]
end
File.absolute_path(File.join(__FILE__, "../../../config/product_info.toml"))
end
|
permalink
#lookup(parent_id, parent_version) ⇒ Object
[View source]
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/license_acceptance/product_reader.rb', line 61
def lookup(parent_id, parent_version)
parent_product = products.fetch(parent_id) do
raise UnknownProduct.new(parent_id)
end
children = relationships.fetch(parent_product, [])
unless parent_version.is_a? String
raise ProductVersionTypeError.new(parent_version)
end
ProductRelationship.new(parent_product, children, parent_version)
end
|
permalink
#lookup_by_mixlib(mixlib_name) ⇒ Object
[View source]
73
74
75
76
77
78
|
# File 'lib/license_acceptance/product_reader.rb', line 73
def lookup_by_mixlib(mixlib_name)
found_product = products.values.find(nil) do |p|
p.mixlib_name == mixlib_name
end
found_product
end
|
[View source]
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?
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
|